/** * Add a service under a path for the current user * @param serviceClass service class to use under ~user * @param serviceName name of the service * @param record service record * @param deleteTreeFirst perform recursive delete of the path first * @return the path the service was created at * @throws IOException */ public String registerSelf( ServiceRecord record, boolean deleteTreeFirst) throws IOException { selfRegistrationPath = putService(user, sliderServiceClass, instanceName, record, deleteTreeFirst); setSelfRegistration(record); return selfRegistrationPath; }
/** * build the zookeeper registry path. * * @return the path the service registered at * @throws NullPointerException if the service has not yet registered */ private String getZkRegistryPath() { Preconditions.checkNotNull(yarnRegistry, "Yarn registry not bound"); String path = yarnRegistry.getAbsoluteSelfRegistrationPath(); Preconditions.checkNotNull(path, "Service record path not defined"); return path; }
/** * Add a component under the slider name/entry * @param componentName component name * @param record record to put * @throws IOException */ public void putComponent(String componentName, ServiceRecord record) throws IOException { putComponent(sliderServiceClass, instanceName, componentName, record); }
yarnRegistryOperations = new YarnRegistryViewForProviders( registryOperations, service_user_name, yarnRegistryOperations.registerSelf(serviceRecord, true); log.info("Registered service under {}; absolute path {}", yarnRegistryOperations.getSelfRegistrationPath(), yarnRegistryOperations.getAbsoluteSelfRegistrationPath()); yarnRegistryOperations.deleteChildren( yarnRegistryOperations.getSelfRegistrationPath(), true);
protected YarnRegistryViewForProviders createYarnRegistryViewForProviders( Configuration conf) throws IOException { conf.set(RegistryConstants.KEY_REGISTRY_ZK_ROOT, RegistryConstants.DEFAULT_ZK_REGISTRY_ROOT); RegistryOperations registryOperations = new MockRegistryOperations(); registryOperations.init(conf); YarnRegistryViewForProviders registryViewForProviders = new YarnRegistryViewForProviders(registryOperations, "hbase", SliderKeys.APP_TYPE, "hbase1", new MockApplicationAttemptId(new MockApplicationId(1), 1)); registryViewForProviders.registerSelf(new ServiceRecord(), true); return registryViewForProviders; }
private void registerHBaseServiceEntry() throws IOException { String name = amState.getApplicationName() ; ServiceRecord serviceRecord = new ServiceRecord(); // bond lifespan to the application serviceRecord.set(YarnRegistryAttributes.YARN_ID, yarnRegistry.getApplicationAttemptId() .getApplicationId().toString()); serviceRecord.set(YarnRegistryAttributes.YARN_PERSISTENCE, PersistencePolicies.APPLICATION); try { URL configURL = new URL(amWebAPI, SLIDER_PATH_PUBLISHER + "/" + HBASE_SERVICE_TYPE); serviceRecord.addExternalEndpoint( RegistryTypeUtils.restEndpoint( CustomRegistryConstants.PUBLISHER_CONFIGURATIONS_API, configURL.toURI())); } catch (URISyntaxException e) { log.warn("failed to create config URL: {}", e, e); } log.info("registering {}/{}", name, HBASE_SERVICE_TYPE); yarnRegistry.putService(HBASE_SERVICE_TYPE, name, serviceRecord, true); PublishedConfiguration publishedSite = new PublishedConfiguration("HBase site", siteConf); PublishedConfigSet configSet = amState.getOrCreatePublishedConfigSet(HBASE_SERVICE_TYPE); configSet.put(HBASE_SITE_PUBLISHED_CONFIG, publishedSite); }
/** * Update the self record by pushing out the latest version of the service * registration record. * @throws IOException any failure. */ public void updateSelf() throws IOException { putService(user, sliderServiceClass, instanceName, selfRegistration, false); }
@Override public void buildEndpointDetails(Map<String, MonitorDetail> details) { ServiceRecord self = yarnRegistry.getSelfRegistration(); List<Endpoint> externals = self.external; for (Endpoint endpoint : externals) { String addressType = endpoint.addressType; if (AddressTypes.ADDRESS_URI.equals(addressType)) { try { List<URL> urls = RegistryTypeUtils.retrieveAddressURLs(endpoint); if (!urls.isEmpty()) { details.put(endpoint.api, new MonitorDetail(urls.get(0).toString(), true)); } } catch (InvalidRecordException | MalformedURLException ignored) { // Ignored } } } }
/** * Handler for {@link UnregisterComponentInstance} * * unregister a component. At the time this message is received, * the component may not have been registered * @param id the component */ public void unregisterComponent(ContainerId id) { log.info("Unregistering component {}", id); if (yarnRegistryOperations == null) { log.warn("Processing unregister component event before initialization " + "completed; init flag ={}", initCompleted); return; } String cid = RegistryPathUtils.encodeYarnID(id.toString()); try { yarnRegistryOperations.deleteComponent(cid); } catch (IOException e) { log.warn("Failed to delete container {} : {}", id, e, e); } }
yarnRegistryOperations = new YarnRegistryViewForProviders( registryOperations, service_user_name, yarnRegistryOperations.registerSelf(serviceRecord, true); log.info("Registered service under {}; absolute path {}", yarnRegistryOperations.getSelfRegistrationPath(), yarnRegistryOperations.getAbsoluteSelfRegistrationPath()); yarnRegistryOperations.deleteChildren( yarnRegistryOperations.getSelfRegistrationPath(), true);
protected YarnRegistryViewForProviders createYarnRegistryViewForProviders( Configuration conf) throws IOException { conf.set(RegistryConstants.KEY_REGISTRY_ZK_ROOT, RegistryConstants.DEFAULT_ZK_REGISTRY_ROOT); RegistryOperations registryOperations = new MockRegistryOperations(); registryOperations.init(conf); YarnRegistryViewForProviders registryViewForProviders = new YarnRegistryViewForProviders(registryOperations, "hbase", SliderKeys.APP_TYPE, "hbase1", new MockApplicationAttemptId(new MockApplicationId(1), 1)); registryViewForProviders.registerSelf(new ServiceRecord(), true); return registryViewForProviders; }
/** * Update the self record by pushing out the latest version of the service * registration record. * @throws IOException any failure. */ public void updateSelf() throws IOException { putService(user, sliderServiceClass, instanceName, selfRegistration, false); }
@Override public void buildEndpointDetails(Map<String, MonitorDetail> details) { ServiceRecord self = yarnRegistry.getSelfRegistration(); List<Endpoint> externals = self.external; for (Endpoint endpoint : externals) { String addressType = endpoint.addressType; if (AddressTypes.ADDRESS_URI.equals(addressType)) { try { List<URL> urls = RegistryTypeUtils.retrieveAddressURLs(endpoint); if (!urls.isEmpty()) { details.put(endpoint.api, new MonitorDetail(urls.get(0).toString(), true)); } } catch (InvalidRecordException | MalformedURLException ignored) { // Ignored } } } }
/** * Handler for {@link UnregisterComponentInstance} * * unregister a component. At the time this message is received, * the component may not have been registered * @param id the component */ public void unregisterComponent(ContainerId id) { log.info("Unregistering component {}", id); if (yarnRegistryOperations == null) { log.warn("Processing unregister component event before initialization " + "completed; init flag ={}", initCompleted); return; } String cid = RegistryPathUtils.encodeYarnID(id.toString()); try { yarnRegistryOperations.deleteComponent(cid); } catch (IOException e) { log.warn("Failed to delete container {} : {}", id, e, e); } }
/** * Add a service under a path for the current user * @param serviceClass service class to use under ~user * @param serviceName name of the service * @param record service record * @param deleteTreeFirst perform recursive delete of the path first * @return the path the service was created at * @throws IOException */ public String registerSelf( ServiceRecord record, boolean deleteTreeFirst) throws IOException { selfRegistrationPath = putService(user, sliderServiceClass, instanceName, record, deleteTreeFirst); setSelfRegistration(record); return selfRegistrationPath; }
/** * Add a service under a path for the current user * @param serviceClass service class to use under ~user * @param serviceName name of the service * @param record service record * @param deleteTreeFirst perform recursive delete of the path first * @return the path the service was created at * @throws IOException */ public String putService( String serviceClass, String serviceName, ServiceRecord record, boolean deleteTreeFirst) throws IOException { return putService(user, serviceClass, serviceName, record, deleteTreeFirst); }
/** * Add a component under the slider name/entry * @param componentName component name * @param record record to put * @throws IOException */ public void putComponent(String componentName, ServiceRecord record) throws IOException { putComponent(sliderServiceClass, instanceName, componentName, record); }
/** * build the zookeeper registry path. * * @return the path the service registered at * @throws NullPointerException if the service has not yet registered */ private String getZkRegistryPath() { Preconditions.checkNotNull(yarnRegistry, "Yarn registry not bound"); String path = yarnRegistry.getAbsoluteSelfRegistrationPath(); Preconditions.checkNotNull(path, "Service record path not defined"); return path; }
/** * Add a service under a path for the current user * @param serviceClass service class to use under ~user * @param serviceName name of the service * @param record service record * @param deleteTreeFirst perform recursive delete of the path first * @return the path the service was created at * @throws IOException */ public String putService( String serviceClass, String serviceName, ServiceRecord record, boolean deleteTreeFirst) throws IOException { return putService(user, serviceClass, serviceName, record, deleteTreeFirst); }
setProvidedServiceRecordAttributes(compOps, container); try { yarnRegistryOperations.putComponent(cid, container); } catch (IOException e) { log.warn("Failed to register container {}/{}: {}",