Search in sources :

Example 6 with AgentConfiguration

use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.

the class ProxyCheckInScheduler method updateConfiguration.

@VisibleForTesting
void updateConfiguration() {
    try {
        AgentConfiguration config = checkin();
        if (config != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Server configuration getShutOffAgents: " + config.getShutOffAgents());
                logger.debug("Server configuration isTruncateQueue: " + config.isTruncateQueue());
            }
            if (config.getShutOffAgents()) {
                logger.warn(firstNonNull(config.getShutOffMessage(), "Shutting down: Server side flag indicating proxy has to shut down."));
                shutdownHook.run();
            } else if (config.isTruncateQueue()) {
                logger.warn("Truncating queue: Server side flag indicating proxy queue has to be truncated.");
                truncateBacklog.run();
            } else {
                agentConfigurationConsumer.accept(config);
            }
        }
    } catch (Exception e) {
        logger.error("Exception occurred during configuration update", e);
    }
}
Also used : AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) ClientErrorException(javax.ws.rs.ClientErrorException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) UnknownHostException(java.net.UnknownHostException) ProcessingException(javax.ws.rs.ProcessingException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with AgentConfiguration

use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testHttpErrors.

@Test
public void testHttpErrors() {
    ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
    ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
    APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
    reset(proxyConfig, proxyV2API, proxyConfig);
    expect(proxyConfig.getServer()).andReturn("https://acme.corp/zzz").anyTimes();
    expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
    expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
    expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
    expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
    String authHeader = "Bearer abcde12345";
    AgentConfiguration returnConfig = new AgentConfiguration();
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    // we need to allow 1 successful checking to prevent early termination
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(401).build())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(403).build())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(407).build())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(408).build())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(429).build())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ServerErrorException(Response.status(500).build())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ServerErrorException(Response.status(502).build())).once();
    replay(proxyV2API, apiContainer);
    ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> assertNull(x.getPointsPerBatch()), () -> {
    }, () -> {
    });
    scheduler.updateProxyMetrics();
    scheduler.updateConfiguration();
    scheduler.updateProxyMetrics();
    scheduler.updateConfiguration();
    scheduler.updateProxyMetrics();
    scheduler.updateConfiguration();
    scheduler.updateProxyMetrics();
    scheduler.updateConfiguration();
    scheduler.updateProxyMetrics();
    scheduler.updateConfiguration();
    scheduler.updateProxyMetrics();
    scheduler.updateConfiguration();
    scheduler.updateProxyMetrics();
    scheduler.updateConfiguration();
    verify(proxyConfig, proxyV2API, apiContainer);
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) ClientErrorException(javax.ws.rs.ClientErrorException) ServerErrorException(javax.ws.rs.ServerErrorException) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with AgentConfiguration

use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testNormalCheckin.

@Test
public void testNormalCheckin() {
    ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
    ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
    APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
    reset(proxyConfig, proxyV2API, proxyConfig);
    expect(proxyConfig.getServer()).andReturn("https://acme.corp/api/").anyTimes();
    expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
    expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
    expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
    expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
    String authHeader = "Bearer abcde12345";
    AgentConfiguration returnConfig = new AgentConfiguration();
    returnConfig.setPointsPerBatch(1234567L);
    returnConfig.currentTime = System.currentTimeMillis();
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).once();
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    replay(proxyV2API, apiContainer);
    ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> assertEquals(1234567L, x.getPointsPerBatch().longValue()), () -> {
    }, () -> {
    });
    scheduler.scheduleCheckins();
    verify(proxyConfig, proxyV2API, apiContainer);
    assertEquals(1, scheduler.getSuccessfulCheckinCount());
    scheduler.shutdown();
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) UUID(java.util.UUID) Test(org.junit.Test)

Example 9 with AgentConfiguration

use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testRetryCheckinOnMisconfiguredUrl.

@Test
public void testRetryCheckinOnMisconfiguredUrl() {
    ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
    ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
    APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
    reset(proxyConfig, proxyV2API, proxyConfig);
    expect(proxyConfig.getServer()).andReturn("https://acme.corp/zzz").anyTimes();
    expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
    expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
    expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
    expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
    String authHeader = "Bearer abcde12345";
    AgentConfiguration returnConfig = new AgentConfiguration();
    returnConfig.setPointsPerBatch(1234567L);
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(404).build())).once();
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    apiContainer.updateServerEndpointURL("https://acme.corp/zzz/api/");
    expectLastCall().once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).once();
    replay(proxyV2API, apiContainer);
    ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> assertEquals(1234567L, x.getPointsPerBatch().longValue()), () -> {
    }, () -> {
    });
    verify(proxyConfig, proxyV2API, apiContainer);
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) ClientErrorException(javax.ws.rs.ClientErrorException) UUID(java.util.UUID) Test(org.junit.Test)

Example 10 with AgentConfiguration

use of com.wavefront.api.agent.AgentConfiguration in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testRetryCheckinOnMisconfiguredUrlFailsTwiceTerminates.

@Test
public void testRetryCheckinOnMisconfiguredUrlFailsTwiceTerminates() {
    ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
    ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
    APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
    reset(proxyConfig, proxyV2API, proxyConfig);
    expect(proxyConfig.getServer()).andReturn("https://acme.corp/zzz").anyTimes();
    expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
    expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
    expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
    expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
    String authHeader = "Bearer abcde12345";
    AgentConfiguration returnConfig = new AgentConfiguration();
    returnConfig.setPointsPerBatch(1234567L);
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(404).build())).times(2);
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    apiContainer.updateServerEndpointURL("https://acme.corp/zzz/api/");
    expectLastCall().once();
    replay(proxyV2API, apiContainer);
    try {
        ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> fail("We are not supposed to get here"), () -> {
        }, () -> {
        });
        fail();
    } catch (RuntimeException e) {
    // 
    }
    verify(proxyConfig, proxyV2API, apiContainer);
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) ClientErrorException(javax.ws.rs.ClientErrorException) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

AgentConfiguration (com.wavefront.api.agent.AgentConfiguration)13 Test (org.junit.Test)10 APIContainer (com.wavefront.agent.api.APIContainer)9 ProxyV2API (com.wavefront.api.ProxyV2API)9 UUID (java.util.UUID)9 ClientErrorException (javax.ws.rs.ClientErrorException)8 ConnectException (java.net.ConnectException)4 SocketTimeoutException (java.net.SocketTimeoutException)4 UnknownHostException (java.net.UnknownHostException)4 ProcessingException (javax.ws.rs.ProcessingException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 ServerErrorException (javax.ws.rs.ServerErrorException)1