@Override public RegistrationHandle register(DrillbitEndpoint data) { try { ServiceInstance<DrillbitEndpoint> serviceInstance = newServiceInstance( data); discovery.registerService(serviceInstance); return new ZKRegistrationHandle(serviceInstance.getId(), data); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } }
@Override public String getInstanceId() { return instance.getId(); } };
@Override public String getInstanceId() { return this.serviceInstance.getId(); }
public ServiceDiscoveryEtcdImpl(EtcdClient client, String basePath, InstanceSerializer<T> serializer, ServiceInstance<T> thisInstance) { this.client = client; this.basePath = basePath; this.serializer = serializer; executor = Executors.newSingleThreadScheduledExecutor(); if (thisInstance != null) { services.put(thisInstance.getId(), thisInstance); } }
static <T> Set<ServiceInstance<T>> filter( Set<ServiceInstance<T>> instances, Set<RegistrationHolder<ServiceInstance<T>>> registrations) { List<ServiceInstance<T>> toRemove = new ArrayList<>(); for (ServiceInstance<T> instance : instances) { String id = instance.getId(); for (RegistrationHolder<ServiceInstance<T>> holder : registrations) { if (holder.svc().getId().equals(id)) { toRemove.add(instance); } } } instances.removeAll(toRemove); return instances; } }
/** * Unregister/remove a group instance * * @param service the group * @throws Exception errors */ @Override public void unregisterService(ServiceInstance<T> service) throws Exception { Entry<T> entry = services.remove(service.getId()); internalUnregisterService(entry); }
@Override public void registerService(ServiceInstance<T> service) throws Exception { services.put(service.getId(), service); internalRegisterService(service); }
/** * Unregister/remove a service instance * * @param service the service * @throws Exception errors */ @Override public void unregisterService(ServiceInstance<T> service) throws Exception { Entry<T> entry = services.remove(service.getId()); internalUnregisterService(entry); }
@Override public void updateService(ServiceInstance<T> service) throws Exception { Preconditions.checkArgument(services.containsKey(service.getId()), "Service is not registered: " + service); byte[] bytes = serializer.serialize(service); String path = String.format("%s/instance", pathForInstance(service.getName(), service.getId())); client.set(path, Base64.encodeBase64String(bytes)); }
@Override public void updateService(final ServiceInstance<T> service) throws Exception { Entry<T> entry = services.get(service.getId()); if ( entry == null ) { throw new Exception("Service not registered: " + service); } synchronized(entry) { entry.service = service; byte[] bytes = serializer.serialize(service); String path = pathForInstance(service.getName(), service.getId()); client.setData().forPath(path, bytes); } }
private DiscoveryInstance toSoaInstance(ServiceInstance<Payload> instance) { if ( instance == null ) { return null; } Payload payload = instance.getPayload(); int port = Objects.firstNonNull(instance.getPort(), Objects.firstNonNull(instance.getSslPort(), 0)); return new DiscoveryInstanceImpl(instance.getId(), instance.getAddress(), port, instance.getSslPort() != null, payload); }
@Override public boolean apply(ServiceInstance<Payload> instance) { SoaFeatures soaFeatures = SoaBundle.getFeatures(environment); return soaFeatures.getDeploymentGroupManager().isAnyGroupEnabled(serviceName, instance.getPayload().getDeploymentGroups()) && instanceToFind.getId().equals(instance.getId()); } },
@Override public RegistrationHandle register(DrillbitEndpoint data) { try { data = data.toBuilder().setState(State.ONLINE).build(); ServiceInstance<DrillbitEndpoint> serviceInstance = newServiceInstance(data); discovery.registerService(serviceInstance); return new ZKRegistrationHandle(serviceInstance.getId(),data); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } }
@Override public byte[] serialize(ServiceInstance<DrillbitEndpoint> i) throws Exception { DrillServiceInstance.Builder b = DrillServiceInstance.newBuilder(); b.setId(i.getId()); b.setRegistrationTimeUTC(i.getRegistrationTimeUTC()); b.setEndpoint(i.getPayload()); return b.build().toByteArray(); }
@Override public byte[] serialize(ServiceInstance<NodeEndpoint> i) throws Exception { DremioServiceInstance.Builder b = DremioServiceInstance.newBuilder(); b.setId(i.getId()); b.setName(i.getName()); b.setRegistrationTimeUTC(i.getRegistrationTimeUTC()); b.setEndpoint(i.getPayload()); return b.build().toByteArray(); }
@Override public byte[] serialize(ServiceInstance<T> instance) throws Exception { if ( compatibleSerializationMode ) { OldServiceInstance<T> compatible = new OldServiceInstance<T>(instance.getName(), instance.getId(), instance.getAddress(), instance.getPort(), instance.getSslPort(), instance.getPayload(), instance.getRegistrationTimeUTC(), instance.getServiceType(), instance.getUriSpec()); return mapper.writeValueAsBytes(compatible); } return mapper.writeValueAsBytes(instance); } }
public static UnitInstance unitInstance(ServiceInstance<UnitProxy> serviceInstance) { if (serviceInstance == null) return null; UnitInstance unitInstance = new UnitInstance(); unitInstance.setId(serviceInstance.getId()); unitInstance.setAddress(serviceInstance.getAddress()); unitInstance.setEnabled(serviceInstance.isEnabled()); unitInstance.setName(serviceInstance.getName()); unitInstance.setPayload(serviceInstance.getPayload()); unitInstance.setPort(serviceInstance.getPort()); unitInstance.setRegistrationTimestamp(serviceInstance.getRegistrationTimeUTC()); return unitInstance; }
public static GroupInstance groupInstance(ServiceInstance<GroupProxy> curatorServiceInstance) { if (curatorServiceInstance == null) return null; GroupInstance groupInstance = new GroupInstance(); groupInstance.setId(curatorServiceInstance.getId()); groupInstance.setAddress(curatorServiceInstance.getAddress()); groupInstance.setEnabled(curatorServiceInstance.isEnabled()); groupInstance.setName(curatorServiceInstance.getName()); groupInstance.setPayload(curatorServiceInstance.getPayload()); groupInstance.setPort(curatorServiceInstance.getPort()); groupInstance.setRegistrationTimestamp(curatorServiceInstance.getRegistrationTimeUTC()); return groupInstance; }
public static ApplicationInstance applicationInstance(ServiceInstance<NodeStatus> serviceInstance) { if (serviceInstance == null) return null; ApplicationInstance applicationInstance = new ApplicationInstance(); applicationInstance.setAddress(serviceInstance.getAddress()); applicationInstance.setEnabled(serviceInstance.isEnabled()); applicationInstance.setId(serviceInstance.getId()); applicationInstance.setName(serviceInstance.getName()); applicationInstance.setPayload(serviceInstance.getPayload()); applicationInstance.setPort(serviceInstance.getPort()); applicationInstance.setRegistrationTimestamp(serviceInstance.getRegistrationTimeUTC()); return applicationInstance; }