@Override public void unregister(RegistrationHandle handle) { if (!(handle instanceof ZKRegistrationHandle)) { throw new UnsupportedOperationException( "Unknown handle type: " + handle.getClass().getName()); } // when Drillbit is unregistered, clean all the listeners registered in CC. this.listeners.clear(); ZKRegistrationHandle h = (ZKRegistrationHandle) handle; try { ServiceInstance<DrillbitEndpoint> serviceInstance = ServiceInstance .<DrillbitEndpoint> builder().address("").port(0).id(h.id) .name(serviceName).build(); discovery.unregisterService(serviceInstance); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } }
.name(serviceName) .uriSpec(URI_SPEC) .address(addr.getAddress().getHostAddress()) .port(addr.getPort()) .build();
instance = ServiceInstance.<Void>builder() .name(serviceName) .address(service.getHost()) .port(service.getPlaintextPort()) .sslPort(service.getTlsPort())
private ServiceDiscovery createAndAnnounceServices(List<String> serviceNames) throws Exception { int port = 1000; ServiceDiscovery<Void> serviceDiscovery = ServiceDiscoveryBuilder.builder(Void.class) .basePath("/test") .client(curator) .build(); for (String serviceName : serviceNames) { String serviceNameToUse = CuratorServiceUtils.makeCanonicalServiceName(serviceName); ServiceInstance instance = ServiceInstance.<Void>builder() .name(serviceNameToUse) .address("localhost") .port(port++) .build(); serviceDiscovery.registerService(instance); } return serviceDiscovery; }
}; ServiceInstanceBuilder<ModelEndpoint> builder = ServiceInstance.<ModelEndpoint> builder() .address(endpointUrl.getHost()) .id(containerId) .name(name)
public RegistrationBuilder address(String address) { this.builder.address(address); return this; }
private ServiceInstance<ModelEndpoint> createInstance(ModelEndpoint ep) throws Exception { URL url = new URL(ep.getEndpoint().getUrl()); ServiceInstanceBuilder<ModelEndpoint> builder = ServiceInstance.<ModelEndpoint> builder() .address(url.getHost()) .id(ep.getContainerId()) .name(ep.getName()) .port(url.getPort()) .registrationTimeUTC(System.currentTimeMillis()) .serviceType(ServiceType.STATIC) .payload(ep) ; return builder.build(); }
.address(endpointUrl.getHost()) .id("0") .name("dga")
public void unregisterService(String serviceName, int port) throws Exception{ String localIp = getInnerHostIp(); String id = serviceName.substring(serviceName.lastIndexOf(".")+1) + ":"+localIp+":"+port; ServiceInstance<InstanceDetails> service = ServiceInstance.<InstanceDetails>builder() .name(serviceName) .address(getInnerHostIp()) .port(port) .id(id) .serviceType(ServiceType.DYNAMIC) .payload(new InstanceDetails(id)).build(); serviceDiscovery.unregisterService(service); logger.info("unregisterService|serviceName=" + serviceName + "|port=" + port); }
public void registerService(String serviceName, int port) throws Exception{ String localIp = getInnerHostIp(); String id = serviceName.substring(serviceName.lastIndexOf(".")+1) + ":"+localIp+":"+port; ServiceInstance<InstanceDetails> service = ServiceInstance.<InstanceDetails>builder() .name(serviceName) .address(getInnerHostIp()) .port(port) .id(id) .serviceType(ServiceType.DYNAMIC) .payload(new InstanceDetails(id)).build(); serviceDiscovery.registerService(service); logger.info("registerService|serviceName=" + serviceName + "|port=" + port); }
private ServiceInstance<WorkerMetadata> getServiceInstance() throws Exception { WorkerMetadata workerMetadata = new WorkerMetadata(workerId, listenAddress, listenPort); return ServiceInstance.<WorkerMetadata>builder() .name(zookeeperConfig.getWorkerServiceName()) .address(listenAddress) .port(listenPort) .id(workerId.toString()) .payload(workerMetadata) .build(); }
protected ServiceInstance serviceInstance(StubConfiguration stubConfiguration, int port) { try { return ServiceInstance.builder() .uriSpec(new UriSpec(this.zookeeperDiscoveryProperties.getUriSpec())) .address("localhost").port(port).name(name(stubConfiguration)) .build(); } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public ServiceInstance<String> getInstance(String serviceName) throws Exception { String url = Configuration.getInstance().getString(serviceName); if(url == null) { return null; } return ServiceInstance.<String>builder() .name(serviceName) .payload("") .address(url) .uriSpec(new UriSpec("{address}")) .build(); }
public static ServiceInstance<NodeStatus> curatorServiceInstance(ApplicationInstance applicationInstance) { try { return ServiceInstance.<NodeStatus>builder() .address(/*applicationInstance.getPayload().getHost()*/applicationInstance.getAddress()) .enabled(true) .id(applicationInstance.getId()) .name(applicationInstance.getName()) .port(applicationInstance.getPort()) .payload(applicationInstance.getPayload()) .build(); } catch (Exception e) { throw new RuntimeException(e); } }
public static ServiceInstance<UnitProxy> curatorServiceInstance(UnitInstance unitInstance) { try { return ServiceInstance.<UnitProxy>builder() .address(unitInstance.getAddress()) .enabled(true) .id(unitInstance.getId()) .name(unitInstance.getName()) .port(unitInstance.getPort()) .payload(unitInstance.getPayload()) .build(); } catch (Exception e) { throw new RuntimeException(e); } }
private void prepareServiceInstance() throws Exception { Address privateAddress = thisNode.getPrivateAddress(); serviceInstance = ServiceInstance.<Void>builder() .uriSpec(new UriSpec("{scheme}://{address}:{port}")) .address(privateAddress.getHost()) .port(privateAddress.getPort()) .name(group) .build(); }
public static ServiceInstance<GroupProxy> curatorServiceInstance(GroupInstance groupInstance) { try { return ServiceInstance.<GroupProxy>builder() .address(groupInstance.getAddress()) .enabled(true) .id(groupInstance.getId()) .name(groupInstance.getName()) .port(groupInstance.getPort()) .payload(groupInstance.getPayload()) .build(); } catch (Exception e) { throw new RuntimeException(e); } }
public static ServiceInstance<NodeStatus> thisCuratorServiceInstance() throws Exception { return ServiceInstance.<NodeStatus>builder() .address(EnvUtil.getLocalIp()) .enabled(true) .id(LocalNodeManager.LOCAL_NODE_ID) .name(EnvUtil.getApplication()) .port(Node.RPC_PORT) .payload(LocalNodeManager.singleton.getFullStatus()) .build(); }
public static ServiceInstance<GroupProxy> thisCuratorServiceInstance(String groupName) throws Exception { return ServiceInstance.<GroupProxy>builder() .address(EnvUtil.getLocalIp()) .enabled(true) .id(new GroupInstanceIdBean(groupName, LocalNodeManager.LOCAL_NODE_ID).getGroupInstanceId()) .name(groupName) .port(Node.RPC_PORT) .payload(GroupProxy.create(LocalUnitsManager.getGroupByName(groupName))) .build(); }
public static ServiceInstance<UnitProxy> thisCuratorServiceInstance(Unit unit) throws Exception { String fullUnitName = Unit.fullName(unit); return ServiceInstance.<UnitProxy>builder() .address(EnvUtil.getLocalIp()) .enabled(true) .id(new UnitInstanceIdBean(fullUnitName, LocalNodeManager.LOCAL_NODE_ID).getUnitInstanceId()) .name(fullUnitName) .port(Node.RPC_PORT) .payload(UnitProxy.create(unit)) .serviceType(ServiceType.DYNAMIC) .build(); }