/** * Returns the index of this Oozie Server in ZooKeeper's list of Oozie Servers (ordered by registration time) * * @param oozies The collection of metadata provided by all of the Oozie Servers (from calling {@link ZKUtils#getAllMetaData()} * @return the index of this Oozie Server in ZooKeeper's list of Oozie Servers (ordered by registration time) */ public int getZKIdIndex(List<ServiceInstance<Map>> oozies) { int index = 0; // We don't actually have to sort all of the IDs, we can simply find out how many are before our zkId for (ServiceInstance<Map> oozie : oozies) { long otherRegTime = oozie.getRegistrationTimeUTC(); if (otherRegTime < zkRegTime) { index++; } } return index; }
/** * Returns the index of this Oozie Server in ZooKeeper's list of Oozie Servers (ordered by registration time) * * @param oozies The collection of metadata provided by all of the Oozie Servers (from calling {@link ZKUtils#getAllMetaData()} * @return the index of this Oozie Server in ZooKeeper's list of Oozie Servers (ordered by registration time) */ public int getZKIdIndex(List<ServiceInstance<Map>> oozies) { int index = 0; // We don't actually have to sort all of the IDs, we can simply find out how many are before our zkId for (ServiceInstance<Map> oozie : oozies) { long otherRegTime = oozie.getRegistrationTimeUTC(); if (otherRegTime < zkRegTime) { index++; } } return index; }
private void checkService(String name) { try { Collection<ServiceInstance<Object>> instances = discovery.queryForInstances(name); for ( ServiceInstance<Object> instance : instances ) { if ( instance.getServiceType() == ServiceType.STATIC ) { if ( (System.currentTimeMillis() - instance.getRegistrationTimeUTC()) > instanceRefreshMs ) { discovery.unregisterService(instance); } } } } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); log.error(String.format("GC for service: %s", name), e); } } }
localVariables.put(FIELD_PORT, nullCheck(serviceInstance.getPort())); localVariables.put(FIELD_SSL_PORT, nullCheck(serviceInstance.getSslPort())); localVariables.put(FIELD_REGISTRATION_TIME_UTC, nullCheck(serviceInstance.getRegistrationTimeUTC())); localVariables.put(FIELD_SERVICE_TYPE, (serviceInstance.getServiceType() != null) ? serviceInstance.getServiceType().name().toLowerCase() : ""); if ( serviceInstance.getSslPort() != null )
localVariables.put(FIELD_PORT, nullCheck(serviceInstance.getPort())); localVariables.put(FIELD_SSL_PORT, nullCheck(serviceInstance.getSslPort())); localVariables.put(FIELD_REGISTRATION_TIME_UTC, nullCheck(serviceInstance.getRegistrationTimeUTC())); localVariables.put(FIELD_SERVICE_TYPE, (serviceInstance.getServiceType() != null) ? serviceInstance.getServiceType().name().toLowerCase() : ""); if ( serviceInstance.getSslPort() != null )
@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(); }
record.getMetadata().put("zookeeper-address", instance.getAddress()); record.getMetadata().put("zookeeper-registration-time", instance.getRegistrationTimeUTC()); record.getMetadata().put("zookeeper-port", instance.getPort()); record.getMetadata().put("zookeeper-ssl-port", instance.getSslPort());
@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(); }
record.getMetadata().put("zookeeper-address", instance.getAddress()); record.getMetadata().put("zookeeper-registration-time", instance.getRegistrationTimeUTC()); record.getMetadata().put("zookeeper-port", instance.getPort()); record.getMetadata().put("zookeeper-ssl-port", instance.getSslPort());
@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 ServiceInstance<JsonObject> deserialize(byte[] bytes) throws Exception { ServiceInstance rawServiceInstance = this.mapper.readValue(bytes, this.type); ServiceInstanceBuilder<JsonObject> builder = ServiceInstance.<JsonObject>builder() .address(rawServiceInstance.getAddress()) .id(rawServiceInstance.getId()) .name(rawServiceInstance.getName()) .payload(new JsonObject(rawServiceInstance.getPayload().toString())) .registrationTimeUTC(rawServiceInstance.getRegistrationTimeUTC()) .serviceType(rawServiceInstance.getServiceType()); if (rawServiceInstance.getSslPort() != null) { builder.sslPort(rawServiceInstance.getSslPort()); } if (rawServiceInstance.getPort() != null) { builder.sslPort(rawServiceInstance.getPort()); } if (rawServiceInstance.getUriSpec() != null) { builder.uriSpec(rawServiceInstance.getUriSpec()); } return builder.build(); } }
public ServiceInstance<JsonObject> deserialize(byte[] bytes) throws Exception { ServiceInstance rawServiceInstance = this.mapper.readValue(bytes, this.type); ServiceInstanceBuilder<JsonObject> builder = ServiceInstance.<JsonObject>builder() .address(rawServiceInstance.getAddress()) .id(rawServiceInstance.getId()) .name(rawServiceInstance.getName()) .payload(new JsonObject(rawServiceInstance.getPayload().toString())) .registrationTimeUTC(rawServiceInstance.getRegistrationTimeUTC()) .serviceType(rawServiceInstance.getServiceType()); if (rawServiceInstance.getSslPort() != null) { builder.sslPort(rawServiceInstance.getSslPort()); } if (rawServiceInstance.getPort() != null) { builder.sslPort(rawServiceInstance.getPort()); } if (rawServiceInstance.getUriSpec() != null) { builder.uriSpec(rawServiceInstance.getUriSpec()); } return builder.build(); } }
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; }
static<T> ObjectNode writeInstance(ObjectMapper mapper, ServiceInstance<T> instance, DiscoveryContext<T> context) { ObjectNode node = mapper.createObjectNode(); node.put("name", instance.getName()); node.put("id", instance.getId()); node.put("address", instance.getAddress()); putInteger(node, "port", instance.getPort()); putInteger(node, "sslPort", instance.getSslPort()); node.put("registrationTimeUTC", instance.getRegistrationTimeUTC()); node.put("serviceType", instance.getServiceType().name()); try { context.marshallJson(node, "payload", instance.getPayload()); } catch ( Exception e ) { ThreadUtils.checkInterrupted(e); throw new WebApplicationException(e); } return node; }
private void advertiseService() throws Exception { // Advertise on the service discovery new EnsurePath(ZK_BASE_SERVICES_PATH).ensure(client.getZookeeperClient()); InstanceSerializer<Map> instanceSerializer = new FixedJsonInstanceSerializer<Map>(Map.class); sDiscovery = ServiceDiscoveryBuilder.builder(Map.class) .basePath(ZK_BASE_SERVICES_PATH) .client(client) .serializer(instanceSerializer) .build(); sDiscovery.start(); sDiscovery.registerService(getMetadataInstance()); // Create the service discovery cache sCache = sDiscovery.serviceCacheBuilder().name(ZK_OOZIE_SERVICE).build(); sCache.start(); zkRegTime = sDiscovery.queryForInstance(ZK_OOZIE_SERVICE, zkId).getRegistrationTimeUTC(); }
private void advertiseService() throws Exception { // Advertise on the service discovery new EnsurePath(ZK_BASE_SERVICES_PATH).ensure(client.getZookeeperClient()); InstanceSerializer<Map> instanceSerializer = new FixedJsonInstanceSerializer<Map>(Map.class); sDiscovery = ServiceDiscoveryBuilder.builder(Map.class) .basePath(ZK_BASE_SERVICES_PATH) .client(client) .serializer(instanceSerializer) .build(); sDiscovery.start(); sDiscovery.registerService(getMetadataInstance()); // Create the service discovery cache sCache = sDiscovery.serviceCacheBuilder().name(ZK_OOZIE_SERVICE).build(); sCache.start(); zkRegTime = sDiscovery.queryForInstance(ZK_OOZIE_SERVICE, zkId).getRegistrationTimeUTC(); }