本文整理汇总了Java中org.apache.hadoop.registry.client.types.ServiceRecord.set方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceRecord.set方法的具体用法?Java ServiceRecord.set怎么用?Java ServiceRecord.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.registry.client.types.ServiceRecord
的用法示例。
在下文中一共展示了ServiceRecord.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerComponent
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
/**
* Handler for {@link RegisterComponentInstance action}
* Register/re-register an ephemeral container that is already in the app state
* @param id the component
* @param description
*/
public boolean registerComponent(ContainerId id, String description) throws
IOException {
RoleInstance instance = appState.getOwnedContainer(id);
if (instance == null) {
return false;
}
// this is where component registrations go
log.info("Registering component {}", id);
String cid = RegistryPathUtils.encodeYarnID(id.toString());
ServiceRecord container = new ServiceRecord();
container.set(YarnRegistryAttributes.YARN_ID, cid);
container.description = description;
container.set(YarnRegistryAttributes.YARN_PERSISTENCE,
PersistencePolicies.CONTAINER);
try {
yarnRegistryOperations.putComponent(cid, container);
} catch (IOException e) {
log.warn("Failed to register container {}/{}: {}",
id, description, e, e);
}
return true;
}
示例2: needUpgrade
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
public boolean needUpgrade() {
String containerPath = RegistryUtils.componentPath(
JOYConstants.APP_TYPE, this.executorMeta.getInstanceName(),
this.executorMeta.getApplicationId(), this.executorMeta.getRunningContainer());
try {
if (registryOperations.exists(containerPath)) {
ServiceRecord sr = registryOperations.resolve(containerPath);
if (sr.get(JOYConstants.NEED_UPGRADE) != null && sr.get(JOYConstants.NEED_UPGRADE).equals(JOYConstants.TRUE)) {
sr.set(JOYConstants.NEED_UPGRADE, JOYConstants.FALSE);
registryOperations.bind(containerPath, sr, BindFlags.OVERWRITE);
LOG.info(JOYConstants.NEED_UPGRADE);
return true;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
示例3: testPutNoParent
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
@Test
public void testPutNoParent() throws Throwable {
ServiceRecord record = new ServiceRecord();
record.set(YarnRegistryAttributes.YARN_ID, "testPutNoParent");
String path = "/path/without/parent";
try {
operations.bind(path, record, 0);
// didn't get a failure
// trouble
RegistryPathStatus stat = operations.stat(path);
fail("Got a status " + stat);
} catch (PathNotFoundException expected) {
// expected
}
}
示例4: testPutNoParent2
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
@Test(expected = PathNotFoundException.class)
public void testPutNoParent2() throws Throwable {
ServiceRecord record = new ServiceRecord();
record.set(YarnRegistryAttributes.YARN_ID, "testPutNoParent");
String path = "/path/without/parent";
operations.bind(path, record, 0);
}
示例5: testRoundTrip
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
@Test
public void testRoundTrip() throws Throwable {
String persistence = PersistencePolicies.PERMANENT;
ServiceRecord record = createRecord(persistence);
record.set("customkey", "customvalue");
record.set("customkey2", "customvalue2");
RegistryTypeUtils.validateServiceRecord("", record);
LOG.info(marshal.toJson(record));
byte[] bytes = marshal.toBytes(record);
ServiceRecord r2 = marshal.fromBytes("", bytes);
assertMatches(record, r2);
RegistryTypeUtils.validateServiceRecord("", r2);
}
示例6: testUnknownFieldsRoundTrip
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
@Test
public void testUnknownFieldsRoundTrip() throws Throwable {
ServiceRecord record =
createRecord(PersistencePolicies.APPLICATION_ATTEMPT);
record.set("key", "value");
record.set("intval", "2");
assertEquals("value", record.get("key"));
assertEquals("2", record.get("intval"));
assertNull(record.get("null"));
assertEquals("defval", record.get("null", "defval"));
byte[] bytes = marshal.toBytes(record);
ServiceRecord r2 = marshal.fromBytes("", bytes);
assertEquals("value", r2.get("key"));
assertEquals("2", r2.get("intval"));
}
示例7: testFieldPropagationInCopy
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
@Test
public void testFieldPropagationInCopy() throws Throwable {
ServiceRecord record =
createRecord(PersistencePolicies.APPLICATION_ATTEMPT);
record.set("key", "value");
record.set("intval", "2");
ServiceRecord that = new ServiceRecord(record);
assertMatches(record, that);
}
示例8: buildExampleServiceEntry
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
/**
* Create a service entry with the sample endpoints
* @param persistence persistence policy
* @return the record
* @throws IOException on a failure
*/
public static ServiceRecord buildExampleServiceEntry(String persistence) throws
IOException,
URISyntaxException {
ServiceRecord record = new ServiceRecord();
record.set(YarnRegistryAttributes.YARN_ID, "example-0001");
record.set(YarnRegistryAttributes.YARN_PERSISTENCE, persistence);
addSampleEndpoints(record, "namenode");
return record;
}
示例9: createRecord
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
public static ServiceRecord createRecord(String id, String persistence,
String description) {
ServiceRecord serviceRecord = new ServiceRecord();
serviceRecord.set(YarnRegistryAttributes.YARN_ID, id);
serviceRecord.description = description;
serviceRecord.set(YarnRegistryAttributes.YARN_PERSISTENCE, persistence);
return serviceRecord;
}
示例10: setContainerRecord
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
public void setContainerRecord(String containerId, String key, String value) {
ServiceRecord record = containerRecords.get(containerId);
if (record == null) {
record = initContainerServiceRecord();
}
record.set(key, value);
containerRecords.put(containerId, record);
}
示例11: registerHBaseServiceEntry
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
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);
}
示例12: setupServiceRecord
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
private ServiceRecord setupServiceRecord() {
ServiceRecord application = new ServiceRecord();
application.set(YarnRegistryAttributes.YARN_ID, jstormMasterContext.appAttemptID.getApplicationId().toString());
application.description = JOYConstants.AM;
application.set(YarnRegistryAttributes.YARN_PERSISTENCE,
PersistencePolicies.PERMANENT);
Map<String, String> addresses = new HashMap<String, String>();
addresses.put(JOYConstants.HOST, jstormMasterContext.appMasterHostname);
addresses.put(JOYConstants.PORT, String.valueOf(jstormMasterContext.appMasterThriftPort));
Endpoint endpoint = new Endpoint(JOYConstants.HTTP, JOYConstants.HOST_PORT, JOYConstants.RPC, addresses);
application.addExternalEndpoint(endpoint);
return application;
}
示例13: tryHostLock
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
/**
* see if anyone is updating host's port list, if not start , update this host itself
* timeout is 45 seconds
*
* @param hostPath
* @throws InterruptedException
* @throws IOException
*/
private void tryHostLock(String hostPath) throws Exception {
//if path has created 60 seconds ago, then delete
if (registryOperations.exists(hostPath)) {
try {
ServiceRecord host = registryOperations.resolve(hostPath);
Long cTime = Long.parseLong(host.get(JOYConstants.CTIME, JOYConstants.DEFAULT_CTIME));
Date now = new Date();
if (now.getTime() - cTime > JOYConstants.HOST_LOCK_TIMEOUT || cTime > now.getTime())
registryOperations.delete(hostPath, true);
} catch (Exception ex) {
LOG.error(ex);
}
}
int failedCount = JOYConstants.RETRY_TIMES;
while (!registryOperations.mknode(hostPath, true)) {
Thread.sleep(JOYConstants.SLEEP_INTERVAL);
failedCount--;
if (failedCount <= 0)
break;
}
if (failedCount > 0) {
ServiceRecord sr = new ServiceRecord();
Date date = new Date();
date.getTime();
sr.set(JOYConstants.CTIME, String.valueOf(date.getTime()));
registryOperations.bind(hostPath, sr, BindFlags.OVERWRITE);
return;
}
throw new Exception("can't get host lock");
}
示例14: tryHostLock
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
/**
* see if anyone is updating host's port list, if not start , update this host itself
* timeout is 45 seconds
*
* @throws InterruptedException
* @throws IOException
*/
private void tryHostLock() throws Exception {
String hostPath = getHostPath();
//if path has created 60 seconds ago, then delete
if (registryOperations.exists(hostPath)) {
try {
ServiceRecord host = registryOperations.resolve(hostPath);
Long cTime = Long.parseLong(host.get("cTime", "0"));
Date now = new Date();
if (now.getTime() - cTime > 60 * 1000 || cTime > now.getTime())
registryOperations.delete(hostPath, true);
} catch (Exception ex) {
LOG.error(ex);
// registryOperations.delete(hostPath, true);
}
}
int failedCount = 45;
while (!registryOperations.mknode(hostPath, true)) {
Thread.sleep(1000);
failedCount--;
if (failedCount <= 0)
break;
}
if (failedCount > 0) {
ServiceRecord sr = new ServiceRecord();
Date date = new Date();
date.getTime();
sr.set("cTime", String.valueOf(date.getTime()));
registryOperations.bind(hostPath, sr, BindFlags.OVERWRITE);
return;
}
throw new Exception("can't get host lock");
}
示例15: testPurgeEntryCuratorCallback
import org.apache.hadoop.registry.client.types.ServiceRecord; //导入方法依赖的package包/类
@Test
public void testPurgeEntryCuratorCallback() throws Throwable {
String path = "/users/example/hbase/hbase1/";
ServiceRecord written = buildExampleServiceEntry(
PersistencePolicies.APPLICATION_ATTEMPT);
written.set(YarnRegistryAttributes.YARN_ID,
"testAsyncPurgeEntry_attempt_001");
operations.mknode(RegistryPathUtils.parentOf(path), true);
operations.bind(path, written, 0);
ZKPathDumper dump = registry.dumpPath(false);
CuratorEventCatcher events = new CuratorEventCatcher();
LOG.info("Initial state {}", dump);
// container query
String id = written.get(YarnRegistryAttributes.YARN_ID, "");
int opcount = purge("/",
id,
PersistencePolicies.CONTAINER,
RegistryAdminService.PurgePolicy.PurgeAll,
events);
assertPathExists(path);
assertEquals(0, opcount);
assertEquals("Event counter", 0, events.getCount());
// now the application attempt
opcount = purge("/",
id,
PersistencePolicies.APPLICATION_ATTEMPT,
RegistryAdminService.PurgePolicy.PurgeAll,
events);
LOG.info("Final state {}", dump);
assertPathNotFound(path);
assertEquals("wrong no of delete operations in " + dump, 1, opcount);
// and validate the callback event
assertEquals("Event counter", 1, events.getCount());
}