Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Nov 2, 2023
1 parent 8da7812 commit 382cc47
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/main/java/io/cryostat/ConfigProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class ConfigProperties {
public static final String AWS_BUCKET_NAME_ARCHIVES = "storage.buckets.archives.name";
public static final String AWS_EVENT_TEMPLATE_NAME = "storage.buckets.event-templates.name";
public static final String AWS_OBJECT_EXPIRATION_LABELS =
"storage.buckets.archives.expiration-label";

Expand Down
53 changes: 32 additions & 21 deletions src/main/java/io/cryostat/events/EventTemplates.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.Optional;

import org.jsoup.nodes.Document;
import org.openjdk.jmc.common.unit.IConstrainedMap;
import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID;
import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar;
import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLAttributeInstance;
import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLModel;
Expand All @@ -32,7 +36,10 @@

import io.cryostat.core.templates.MutableTemplateService.InvalidEventTemplateException;
import io.cryostat.core.templates.MutableTemplateService.InvalidXmlException;
import io.cryostat.ConfigProperties;
import io.cryostat.core.FlightRecorderException;
import io.cryostat.core.templates.Template;
import io.cryostat.core.templates.TemplateService;
import io.cryostat.core.templates.TemplateType;
import io.cryostat.targets.Target;
import io.cryostat.targets.TargetConnectionManager;
Expand All @@ -56,6 +63,9 @@
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
import software.amazon.awssdk.services.s3.model.HeadBucketRequest;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectTaggingRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;

import org.jboss.resteasy.reactive.RestPath;
import org.jboss.resteasy.reactive.RestResponse;
Expand All @@ -80,8 +90,8 @@ public class EventTemplates {
@Inject S3Client storage;
@Inject Logger logger;

@ConfigProperty(name = "storage.buckets.event-templates.name")
String eventTemplatesBucket;
@ConfigProperty(name = ConfigProperties.AWS_BUCKET_NAME_ARCHIVES)
static String eventTemplatesBucket;

void onStart(@Observes StartupEvent evt) {
boolean exists = false;
Expand Down Expand Up @@ -193,28 +203,29 @@ public String getTargetTemplate(
.toString());
}

// static class S3TemplateService implements TemplateService {
// S3Client s3;
static class S3TemplateService implements TemplateService {
S3Client s3;

// @Override
// public Optional<IConstrainedMap<EventOptionID>> getEvents(String arg0, TemplateType arg1)
// throws FlightRecorderException {
// return Optional.empty();
// }
@Override
public Optional<IConstrainedMap<EventOptionID>> getEvents(String templateName, TemplateType templateType)
throws FlightRecorderException {
return Optional.empty();
}

// @Override
// public List<Template> getTemplates() throws FlightRecorderException {
// var objects = s3.listObjectsV2();
// var templates = convertObjects(objects);
// return templates;
// }
@Override
public List<Template> getTemplates() throws FlightRecorderException {
var builder = ListObjectsV2Request.builder().bucket(eventTemplatesBucket);
var objects = s3.listObjectsV2(builder.build());
var templates = convertObjects(objects);
return templates;
}

// @Override
// public Optional<Document> getXml(String arg0, TemplateType arg1)
// throws FlightRecorderException {
// return Optional.empty();
// }
// }
@Override
public Optional<Document> getXml(String templateName, TemplateType templateType)
throws FlightRecorderException {
return Optional.empty();
}
}

@Blocking
public Template addTemplate(String templateText)
Expand Down
24 changes: 21 additions & 3 deletions src/test/java/io/cryostat/CustomEventTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,43 @@

import static io.cryostat.TestUtils.givenBasicAuth;

import javax.swing.text.AbstractDocument.Content;

import org.apache.http.entity.ContentType;
import org.eclipse.microprofile.openapi.models.media.XML;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import io.cryostat.core.templates.Template;
import io.cryostat.core.templates.TemplateType;
import io.vertx.core.json.JsonObject;
import jakarta.transaction.Transactional;

public class CustomEventTemplate {

Template template;

static String TEMPLATE_NAME = "customEventTemplate";

@BeforeEach
public void setup() {

template = new Template(TEMPLATE_NAME, "desc", "prov", TemplateType.CUSTOM);
}

@AfterEach
@Transactional
public void afterEach() {

template.deleteAll();
}

@Test
public void testCustomEventTemplate() {
givenBasicAuth().get().contentType(XML).then().post().statusCode(200);
givenBasicAuth().get().then().statusCode(200);
}

@Test
public void testCustom() {
givenBasicAuth().body().contentType(ContentType.APPLICATION_XML).post().then().statusCode(200);
}
}

0 comments on commit 382cc47

Please sign in to comment.