Search in sources :

Example 1 with Logger

use of io.cryostat.core.log.Logger in project cryostat by cryostatio.

the class Cryostat method main.

public static void main(String[] args) throws Exception {
    CryostatCore.initialize();
    Security.addProvider(BouncyCastleProviderSingleton.getInstance());
    final Logger logger = Logger.INSTANCE;
    final Environment environment = new Environment();
    logger.trace("env: {}", environment.getEnv().toString());
    logger.info("{} started.", System.getProperty("java.rmi.server.hostname", "cryostat"));
    Client client = DaggerCryostat_Client.builder().build();
    CompletableFuture<Void> future = new CompletableFuture<>();
    client.httpServer().addShutdownListener(() -> future.complete(null));
    client.credentialsManager().load();
    client.ruleRegistry().loadRules();
    client.vertx().deployVerticle(client.httpServer(), new DeploymentOptions(), res -> logger.info("HTTP Server Verticle Started"));
    client.vertx().deployVerticle(client.webServer(), new DeploymentOptions().setWorker(true), res -> logger.info("WebServer Verticle Started"));
    client.vertx().deployVerticle(client.messagingServer(), new DeploymentOptions(), res -> logger.info("MessagingServer Verticle Started"));
    client.vertx().deployVerticle(client.ruleProcessor(), new DeploymentOptions().setWorker(true), res -> logger.info("RuleProcessor Verticle Started"));
    client.platformClient().start();
    client.recordingMetadataManager().load();
    future.join();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) DeploymentOptions(io.vertx.core.DeploymentOptions) Environment(io.cryostat.core.sys.Environment) Logger(io.cryostat.core.log.Logger) PlatformClient(io.cryostat.platform.PlatformClient)

Example 2 with Logger

use of io.cryostat.core.log.Logger in project cryostat by cryostatio.

the class OpenShiftAuthManagerTest method testPropertiesResourceMapProcessing.

@ParameterizedTest
@MethodSource("getResourceMaps")
void testPropertiesResourceMapProcessing(Map<String, Object> map) throws IOException {
    ClassPropertiesLoader loader = Mockito.mock(ClassPropertiesLoader.class);
    Map<String, String> resourcesMap = new HashMap<>();
    map.entrySet().stream().filter(e -> !e.getKey().equals("expected")).forEach(e -> resourcesMap.put((String) e.getKey(), (String) e.getValue()));
    Map<ResourceType, Set<GroupResource>> expected = (Map<ResourceType, Set<GroupResource>>) map.get("expected");
    Mockito.when(loader.loadAsMap(Mockito.any())).thenReturn(resourcesMap);
    Map<ResourceType, Set<GroupResource>> result = OpenShiftAuthManager.processResourceMapping(loader, logger);
    MatcherAssert.assertThat(result, Matchers.equalTo(expected));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BeforeEach(org.junit.jupiter.api.BeforeEach) OpenShiftMockServerExtension(io.fabric8.openshift.client.server.mock.OpenShiftMockServerExtension) URL(java.net.URL) MultiMap(io.vertx.core.MultiMap) Scheduler(com.github.benmanes.caffeine.cache.Scheduler) GroupResource(io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource) UserInfo(io.cryostat.net.UserInfo) Resource(io.fabric8.kubernetes.client.dsl.Resource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) MissingEnvironmentVariableException(io.cryostat.net.MissingEnvironmentVariableException) BeforeAll(org.junit.jupiter.api.BeforeAll) Gson(com.google.gson.Gson) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) AuthenticationScheme(io.cryostat.net.AuthenticationScheme) ResponseBody(okhttp3.ResponseBody) MethodSource(org.junit.jupiter.params.provider.MethodSource) NullAndEmptySource(org.junit.jupiter.params.provider.NullAndEmptySource) Request(okhttp3.Request) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ResourceType(io.cryostat.net.security.ResourceType) Set(java.util.Set) TokenReview(io.fabric8.kubernetes.api.model.authentication.TokenReview) OAuthAccessToken(io.fabric8.openshift.api.model.OAuthAccessToken) HttpHeaders(io.vertx.core.http.HttpHeaders) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Test(org.junit.jupiter.api.Test) Config(io.fabric8.kubernetes.client.Config) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) TokenNotFoundException(io.cryostat.net.TokenNotFoundException) HttpUrl(okhttp3.HttpUrl) MainModule(io.cryostat.MainModule) OAuthAccessTokenList(io.fabric8.openshift.api.model.OAuthAccessTokenList) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) CsvSource(org.junit.jupiter.params.provider.CsvSource) SelfSubjectAccessReviewBuilder(io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReviewBuilder) SelfSubjectAccessReview(io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReview) Mock(org.mockito.Mock) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) EnumSource(org.junit.jupiter.params.provider.EnumSource) ResourceVerb(io.cryostat.net.security.ResourceVerb) Function(java.util.function.Function) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) Logger(io.cryostat.core.log.Logger) Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Environment(io.cryostat.core.sys.Environment) ValueSource(org.junit.jupiter.params.provider.ValueSource) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) PermissionDeniedException(io.cryostat.net.PermissionDeniedException) TokenReviewBuilder(io.fabric8.kubernetes.api.model.authentication.TokenReviewBuilder) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) OkHttpClient(okhttp3.OkHttpClient) Assertions(org.junit.jupiter.api.Assertions) EnableOpenShiftMockClient(io.fabric8.openshift.client.server.mock.EnableOpenShiftMockClient) NullSource(org.junit.jupiter.params.provider.NullSource) ClassPropertiesLoader(io.cryostat.util.resource.ClassPropertiesLoader) ResourceAction(io.cryostat.net.security.ResourceAction) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ResourceType(io.cryostat.net.security.ResourceType) MultiMap(io.vertx.core.MultiMap) Map(java.util.Map) HashMap(java.util.HashMap) GroupResource(io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource) ClassPropertiesLoader(io.cryostat.util.resource.ClassPropertiesLoader) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with Logger

use of io.cryostat.core.log.Logger in project cryostat by cryostatio.

the class PeriodicArchiverTest method setup.

@BeforeEach
void setup() throws Exception {
    this.serviceRef = new ServiceRef(new URI(jmxUrl), "com.example.App");
    this.failureCounter = new AtomicInteger();
    this.rule = new Rule.Builder().name("Test Rule").description("Automated unit test rule").matchExpression("target.alias=='com.example.App'").eventSpecifier("template=Continuous").maxAgeSeconds(30).maxSizeBytes(1234).preservedArchives(2).archivalPeriodSeconds(67).build();
    this.archiver = new PeriodicArchiver(serviceRef, credentialsManager, rule, recordingArchiveHelper, p -> {
        failureCounter.incrementAndGet();
        return null;
    }, logger, base32);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) Matchers(org.hamcrest.Matchers) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ServiceRef(io.cryostat.platform.ServiceRef) RecordingArchiveHelper(io.cryostat.recordings.RecordingArchiveHelper) Base32(org.apache.commons.codec.binary.Base32) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CredentialsManager(io.cryostat.configuration.CredentialsManager) Assertions(org.junit.jupiter.api.Assertions) Logger(io.cryostat.core.log.Logger) URI(java.net.URI) Queue(java.util.Queue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServiceRef(io.cryostat.platform.ServiceRef) URI(java.net.URI) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Logger (io.cryostat.core.log.Logger)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Environment (io.cryostat.core.sys.Environment)2 ExecutionException (java.util.concurrent.ExecutionException)2 MatcherAssert (org.hamcrest.MatcherAssert)2 Matchers (org.hamcrest.Matchers)2 Assertions (org.junit.jupiter.api.Assertions)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 Mock (org.mockito.Mock)2 Mockito (org.mockito.Mockito)2 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)2 Scheduler (com.github.benmanes.caffeine.cache.Scheduler)1 Gson (com.google.gson.Gson)1 MainModule (io.cryostat.MainModule)1 CredentialsManager (io.cryostat.configuration.CredentialsManager)1 AuthenticationScheme (io.cryostat.net.AuthenticationScheme)1 MissingEnvironmentVariableException (io.cryostat.net.MissingEnvironmentVariableException)1 PermissionDeniedException (io.cryostat.net.PermissionDeniedException)1