@Override public DrillbitEndpoint apply( ServiceInstance<DrillbitEndpoint> input) { return input.getPayload(); } });
/** * Reset the state to empty. */ public void resetState() { rwLock.readLock().lock(); ServiceInstance<ModelEndpoint> ep = null; try { for(Map.Entry<String, ServiceInstance<ModelEndpoint>> kv : containerToEndpoint.entrySet()) { ep = kv.getValue(); serviceDiscovery.unregisterService(ep); } } catch (Exception e) { LOG.error("Unable to unregister endpoint " + ep.getPayload(), e); } finally { rwLock.readLock().unlock(); } }
@Override public Map<String, String> getServerMetadata(Server server) { if (server instanceof ZookeeperServer) { ZookeeperServer zookeeperServer = (ZookeeperServer) server; return zookeeperServer.getInstance().getPayload().getMetadata(); } throw new DiscoveryException("Server instance isn't the type of ZookeeperServer"); } }
for(String name : serviceDiscovery.queryForNames()) { for(ServiceInstance<ModelEndpoint> endpoint: serviceDiscovery.queryForInstances(name)) { ModelEndpoint ep = endpoint.getPayload(); if(LOG.isDebugEnabled()) { LOG.debug("Found model endpoint " + ep);
@Override public NodeEndpoint apply(ServiceInstance<NodeEndpoint> input) { return input.getPayload(); } });
@Override public ComponentInfo getComponentInfo() { return registeredInstance.getPayload(); } }
@SuppressWarnings({"unchecked"}) @Override public ServiceInstance<T> deserialize(byte[] bytes) throws Exception { ServiceInstance rawServiceInstance = mapper.readValue(bytes, type); payloadClass.cast(rawServiceInstance.getPayload()); // just to verify that it's the correct type return (ServiceInstance<T>)rawServiceInstance; }
@SuppressWarnings({"unchecked"}) @Override public ServiceInstance<T> deserialize(byte[] bytes) throws Exception { ServiceInstance rawServiceInstance = mapper.readValue(bytes, type); payloadClass.cast(rawServiceInstance.getPayload()); // just to verify that it's the correct type return (ServiceInstance<T>)rawServiceInstance; }
@Override public Map<String, String> getMetadata() { if (this.serviceInstance == null || this.serviceInstance.getPayload() == null) { return Collections.emptyMap(); } return this.serviceInstance.getPayload().getMetadata(); } }
@Override public List<ComponentInfo> getComponents(ComponentCategory category) { try { Collection<ServiceInstance<ComponentInfo>> instances = serviceDiscovery.queryForInstances(category.toString()); List<ComponentInfo> result = new ArrayList<>(instances.size()); instances.forEach(i -> result.add(i.getPayload())); return result; } catch (Exception e) { e.printStackTrace(); } return new ArrayList<ComponentInfo>(); }
@Override public Map<String, String> getMetadata(Server server) { if (server instanceof ZookeeperServer) { ZookeeperServer zookeeperServer = (ZookeeperServer) server; ServiceInstance<ZookeeperInstance> instance = zookeeperServer.getInstance(); if (instance != null && instance.getPayload() != null) { return instance.getPayload().getMetadata(); } } return super.getMetadata(server); } }
@Override public Object getStatus(ZookeeperRegistration registration) { ZookeeperInstance instance = registration.getServiceInstance().getPayload(); String instanceStatus = instance.getMetadata().get(INSTANCE_STATUS_KEY); if (!StringUtils.hasText(instanceStatus)) { instanceStatus = STATUS_UP; } return instanceStatus; }
@Override public Map<String, String> getServerMetadata(Server server) { if (server instanceof ZookeeperServer) { ZookeeperServer zookeeperServer = (ZookeeperServer) server; return zookeeperServer.getInstance().getPayload().getMetadata(); } throw new DiscoveryException("Server instance isn't the type of ZookeeperServer"); } }
@Override public void setStatus(ZookeeperRegistration registration, String status) { ServiceInstance<ZookeeperInstance> serviceInstance = registration.getServiceInstance(); ZookeeperInstance instance = serviceInstance.getPayload(); instance.getMetadata().put(INSTANCE_STATUS_KEY, status); try { getServiceDiscovery().updateService(serviceInstance); } catch (Exception e) { ReflectionUtils.rethrowRuntimeException(e); } }
@Override public ServiceDefinition convert(ZookeeperServer source) { return new DefaultServiceDefinition( source.getId(), source.getHost(), source.getPort(), source.getInstance().getPayload().getMetadata() ); } }
@Test public void test() { final NodeStatus status = new NodeStatus(); status.setActiveCount(1); ServiceInstance<NodeStatus> instance = JSON.parseObject(new JSONObject() {{ put("payload", status); }}.toJSONString(), new TypeReference<ServiceInstance<NodeStatus>>() { }); Assert.assertEquals(instance.getPayload().getActiveCount(), 1); } }
@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; }