Search in sources :

Example 1 with ProxyV2API

use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testDontRetryCheckinOnBadCredentials.

@Test
public void testDontRetryCheckinOnBadCredentials() {
    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);
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(401).build())).once();
    replay(proxyV2API, apiContainer);
    try {
        ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> fail("We are not supposed to get here"), () -> {
        }, () -> {
        });
        fail("We're not supposed to get here");
    } 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)

Example 2 with ProxyV2API

use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testDontRetryCheckinOnMisconfiguredUrlThatEndsWithApi.

@Test
public void testDontRetryCheckinOnMisconfiguredUrlThatEndsWithApi() {
    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);
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(404).build())).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)

Example 3 with ProxyV2API

use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testNormalCheckinWithRemoteShutdown.

@Test
public void testNormalCheckinWithRemoteShutdown() {
    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.setShutOffAgents(true);
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).anyTimes();
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    replay(proxyV2API, apiContainer);
    AtomicBoolean shutdown = new AtomicBoolean(false);
    ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> {
    }, () -> shutdown.set(true), () -> {
    });
    scheduler.updateProxyMetrics();
    scheduler.updateConfiguration();
    verify(proxyConfig, proxyV2API, apiContainer);
    assertTrue(shutdown.get());
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with ProxyV2API

use of com.wavefront.api.ProxyV2API 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 5 with ProxyV2API

use of com.wavefront.api.ProxyV2API 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)

Aggregations

APIContainer (com.wavefront.agent.api.APIContainer)9 ProxyV2API (com.wavefront.api.ProxyV2API)9 AgentConfiguration (com.wavefront.api.agent.AgentConfiguration)9 UUID (java.util.UUID)9 Test (org.junit.Test)9 ClientErrorException (javax.ws.rs.ClientErrorException)5 ConnectException (java.net.ConnectException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ProcessingException (javax.ws.rs.ProcessingException)1 ServerErrorException (javax.ws.rs.ServerErrorException)1