Search in sources :

Example 51 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class AbstractTester method createRemoteApps.

private static Application createRemoteApps() {
    Application myapp = new Application(REMOTE_REGION_APP_NAME);
    InstanceInfo instanceInfo = createRemoteInstance(REMOTE_REGION_INSTANCE_1_HOSTNAME);
    //instanceInfo.setActionType(InstanceInfo.ActionType.MODIFIED);
    myapp.addInstance(instanceInfo);
    return myapp;
}
Also used : Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 52 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class RemoteRegionRegistry method updateDelta.

/**
     * Updates the delta information fetches from the eureka server into the
     * local cache.
     *
     * @param delta
     *            the delta information received from eureka server in the last
     *            poll cycle.
     */
private void updateDelta(Applications delta) {
    int deltaCount = 0;
    for (Application app : delta.getRegisteredApplications()) {
        for (InstanceInfo instance : app.getInstances()) {
            ++deltaCount;
            if (ActionType.ADDED.equals(instance.getActionType())) {
                Application existingApp = getApplications().getRegisteredApplications(instance.getAppName());
                if (existingApp == null) {
                    getApplications().addApplication(app);
                }
                logger.debug("Added instance {} to the existing apps ", instance.getId());
                getApplications().getRegisteredApplications(instance.getAppName()).addInstance(instance);
            } else if (ActionType.MODIFIED.equals(instance.getActionType())) {
                Application existingApp = getApplications().getRegisteredApplications(instance.getAppName());
                if (existingApp == null) {
                    getApplications().addApplication(app);
                }
                logger.debug("Modified instance {} to the existing apps ", instance.getId());
                getApplications().getRegisteredApplications(instance.getAppName()).addInstance(instance);
            } else if (ActionType.DELETED.equals(instance.getActionType())) {
                Application existingApp = getApplications().getRegisteredApplications(instance.getAppName());
                if (existingApp == null) {
                    getApplications().addApplication(app);
                }
                logger.debug("Deleted instance {} to the existing apps ", instance.getId());
                getApplications().getRegisteredApplications(instance.getAppName()).removeInstance(instance);
            }
        }
    }
    logger.debug("The total number of instances fetched by the delta processor : {}", deltaCount);
}
Also used : Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 53 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class StatusUtilTest method getStatusUtil.

/**
     * @param replicas the number of replicas to mock
     * @param instances the number of instances to mock
     * @param minimum the minimum number of peers
     * @return the status utility with the mocked replicas/instances
     */
private StatusUtil getStatusUtil(int replicas, int instances, int minimum) {
    EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class);
    List<InstanceInfo> mockInstanceInfos = getMockInstanceInfos(instances);
    Application mockApplication = mock(Application.class);
    when(mockApplication.getInstances()).thenReturn(mockInstanceInfos);
    ApplicationInfoManager mockAppInfoManager = mock(ApplicationInfoManager.class);
    when(mockAppInfoManager.getInfo()).thenReturn(mockInstanceInfos.get(0));
    when(mockEurekaServerContext.getApplicationInfoManager()).thenReturn(mockAppInfoManager);
    PeerAwareInstanceRegistry mockRegistry = mock(PeerAwareInstanceRegistry.class);
    when(mockRegistry.getApplication("stuff", false)).thenReturn(mockApplication);
    when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry);
    List<PeerEurekaNode> mockNodes = getMockNodes(replicas);
    EurekaTransportConfig mockTransportConfig = mock(EurekaTransportConfig.class);
    when(mockTransportConfig.applicationsResolverUseIp()).thenReturn(false);
    EurekaClientConfig mockClientConfig = mock(EurekaClientConfig.class);
    when(mockClientConfig.getTransportConfig()).thenReturn(mockTransportConfig);
    EurekaServerConfig mockServerConfig = mock(EurekaServerConfig.class);
    when(mockServerConfig.getHealthStatusMinNumberOfAvailablePeers()).thenReturn(minimum);
    PeerEurekaNodes peerEurekaNodes = new PeerEurekaNodes(mockRegistry, mockServerConfig, mockClientConfig, null, mockAppInfoManager);
    PeerEurekaNodes spyPeerEurekaNodes = spy(peerEurekaNodes);
    when(spyPeerEurekaNodes.getPeerEurekaNodes()).thenReturn(mockNodes);
    when(mockEurekaServerContext.getPeerEurekaNodes()).thenReturn(spyPeerEurekaNodes);
    return new StatusUtil(mockEurekaServerContext);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) InstanceInfo(com.netflix.appinfo.InstanceInfo) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) EurekaServerContext(com.netflix.eureka.EurekaServerContext) PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode) PeerEurekaNodes(com.netflix.eureka.cluster.PeerEurekaNodes) EurekaServerConfig(com.netflix.eureka.EurekaServerConfig) EurekaTransportConfig(com.netflix.discovery.shared.transport.EurekaTransportConfig) Application(com.netflix.discovery.shared.Application) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 54 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class ApplicationsResourceTest method testFullAppsGetJson.

@Test
public void testFullAppsGetJson() throws Exception {
    Response response = applicationsResource.getContainers(Version.V2.name(), MediaType.APPLICATION_JSON, // encoding
    null, EurekaAccept.full.name(), // uriInfo
    null, // remote regions
    null);
    String json = String.valueOf(response.getEntity());
    DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
    Applications decoded = decoder.decode(json, Applications.class);
    // test per app as the full apps list include the mock server that is not part of the test apps
    for (Application application : testApplications.getRegisteredApplications()) {
        Application decodedApp = decoded.getRegisteredApplications(application.getName());
        assertThat(EurekaEntityComparators.equal(application, decodedApp), is(true));
    }
}
Also used : Response(javax.ws.rs.core.Response) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 55 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class ApplicationsResourceTest method testMiniAppsGet.

@Test
public void testMiniAppsGet() throws Exception {
    Response response = applicationsResource.getContainers(Version.V2.name(), MediaType.APPLICATION_JSON, // encoding
    null, EurekaAccept.compact.name(), // uriInfo
    null, // remote regions
    null);
    String json = String.valueOf(response.getEntity());
    DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
    Applications decoded = decoder.decode(json, Applications.class);
    // test per app as the full apps list include the mock server that is not part of the test apps
    for (Application application : testApplications.getRegisteredApplications()) {
        Application decodedApp = decoded.getRegisteredApplications(application.getName());
        // assert false as one is mini, so should NOT equal
        assertThat(EurekaEntityComparators.equal(application, decodedApp), is(false));
    }
    for (Application application : testApplications.getRegisteredApplications()) {
        Application decodedApp = decoded.getRegisteredApplications(application.getName());
        assertThat(application.getName(), is(decodedApp.getName()));
        // now do mini equals
        for (InstanceInfo instanceInfo : application.getInstances()) {
            InstanceInfo decodedInfo = decodedApp.getByInstanceId(instanceInfo.getId());
            assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedInfo), is(true));
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Aggregations

Application (com.netflix.discovery.shared.Application)60 InstanceInfo (com.netflix.appinfo.InstanceInfo)35 Applications (com.netflix.discovery.shared.Applications)25 Test (org.junit.Test)18 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)7 HashMap (java.util.HashMap)7 Response (javax.ws.rs.core.Response)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)6 Lease (com.netflix.eureka.lease.Lease)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 EurekaHttpResponseBuilder (com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder)2 PeerEurekaNode (com.netflix.eureka.cluster.PeerEurekaNode)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1