com.netflix.appinfo.MyDataCenterInfo Java Examples

The following examples show how to use com.netflix.appinfo.MyDataCenterInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NacosSyncToEurekaServiceImpl.java    From nacos-sync with Apache License 2.0 5 votes vote down vote up
private InstanceInfo buildSyncInstance(Instance instance, TaskDO taskDO) {
    DataCenterInfo dataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn);
    HashMap<String, String> metadata = new HashMap<>(16);
    metadata.put(SkyWalkerConstants.DEST_CLUSTERID_KEY, taskDO.getDestClusterId());
    metadata.put(SkyWalkerConstants.SYNC_SOURCE_KEY, skyWalkerCacheServices.getClusterType(taskDO.getSourceClusterId()).getCode());
    metadata.put(SkyWalkerConstants.SOURCE_CLUSTERID_KEY, taskDO.getSourceClusterId());
    String homePageUrl = "http://" + instance.getIp() + ":" + instance.getPort();
    String serviceName = taskDO.getServiceName();

    return new InstanceInfo(
            instance.getIp() + ":" + serviceName + ":" + instance.getPort(),
            serviceName,
            null,
            instance.getIp(),
            null,
            new InstanceInfo.PortWrapper(true, instance.getPort()),
            null,
            homePageUrl,
            homePageUrl + "/info",
            homePageUrl + "/health",
            null,
            serviceName,
            serviceName,
            1,
            dataCenterInfo,
            instance.getIp(),
            InstanceInfo.InstanceStatus.UP,
            InstanceInfo.InstanceStatus.UNKNOWN,
            null,
            new LeaseInfo(30, 90,
                    0L, 0L, 0L, 0L, 0L),
            false,
            metadata,
            System.currentTimeMillis(),
            System.currentTimeMillis(),
            null,
            null
    );
}
 
Example #2
Source File: EurekaControllerTest.java    From didi-eureka-server with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class);
	when(peerEurekaNodes.getPeerNodesView()).thenReturn(Collections.<PeerEurekaNode>emptyList());

	InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
			.setAppName("test")
			.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
			.build();

	this.infoManager = mock(ApplicationInfoManager.class);
	this.original = ApplicationInfoManager.getInstance();
	setInstance(this.infoManager);
	when(this.infoManager.getInfo()).thenReturn(instanceInfo);

	Application myapp = new Application("myapp");
	myapp.addInstance(InstanceInfo.Builder.newBuilder()
			.setAppName("myapp")
			.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
			.setInstanceId("myapp:1")
			.build());

	ArrayList<Application> applications = new ArrayList<>();
	applications.add(myapp);

	PeerAwareInstanceRegistry registry = mock(PeerAwareInstanceRegistry.class);
	when(registry.getSortedApplications()).thenReturn(applications);

	EurekaServerContext serverContext = mock(EurekaServerContext.class);
	EurekaServerContextHolder.initialize(serverContext);
	when(serverContext.getRegistry()).thenReturn(registry);
	when(serverContext.getPeerEurekaNodes()).thenReturn(peerEurekaNodes);
	when(serverContext.getApplicationInfoManager()).thenReturn(this.infoManager);

}
 
Example #3
Source File: EurekaControllerTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
	PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class);
	when(peerEurekaNodes.getPeerNodesView())
			.thenReturn(Collections.<PeerEurekaNode>emptyList());

	InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test")
			.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
			.build();

	this.infoManager = mock(ApplicationInfoManager.class);
	this.original = ApplicationInfoManager.getInstance();
	setInstance(this.infoManager);
	when(this.infoManager.getInfo()).thenReturn(instanceInfo);

	Application myapp = new Application("myapp");
	myapp.addInstance(InstanceInfo.Builder.newBuilder().setAppName("myapp")
			.setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
			.setInstanceId("myapp:1").build());

	ArrayList<Application> applications = new ArrayList<>();
	applications.add(myapp);

	PeerAwareInstanceRegistry registry = mock(PeerAwareInstanceRegistry.class);
	when(registry.getSortedApplications()).thenReturn(applications);

	EurekaServerContext serverContext = mock(EurekaServerContext.class);
	EurekaServerContextHolder.initialize(serverContext);
	when(serverContext.getRegistry()).thenReturn(registry);
	when(serverContext.getPeerEurekaNodes()).thenReturn(peerEurekaNodes);
	when(serverContext.getApplicationInfoManager()).thenReturn(this.infoManager);

}
 
Example #4
Source File: LoadBalancerTestUtils.java    From ribbon with Apache License 2.0 5 votes vote down vote up
static List<InstanceInfo> getDummyInstanceInfo(String appName, String host, String ipAddr, int port){
    List<InstanceInfo> list = new ArrayList<InstanceInfo>();

    InstanceInfo info = InstanceInfo.Builder.newBuilder().setAppName(appName)
            .setHostName(host)
            .setIPAddr(ipAddr)
            .setPort(port)
            .setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
            .build();

    list.add(info);

    return list;
}
 
Example #5
Source File: MockedDiscoveryServerListTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
static List<InstanceInfo> getDummyInstanceInfo(String appName, List<Server> serverList){
    List<InstanceInfo> list = new ArrayList<InstanceInfo>();
    for (Server server: serverList) {
        InstanceInfo info = InstanceInfo.Builder.newBuilder().setAppName(appName)
                .setHostName(server.getHost())
                .setPort(server.getPort())
                .setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn))
                .build();
        list.add(info);
    }
    return list;
}