Search in sources :

Example 41 with ServiceRecord

use of org.apache.hadoop.registry.client.types.ServiceRecord in project hive by apache.

the class TezAmRegistryImpl method register.

public String register(int amPort, int pluginPort, String sessionId, String serializedToken, String jobIdForToken, int guaranteedCount) throws IOException {
    if (srv != null) {
        throw new UnsupportedOperationException("Already registered with " + srv);
    }
    srv = new ServiceRecord();
    Endpoint rpcEndpoint = RegistryTypeUtils.ipcEndpoint(IPC_TEZCLIENT, new InetSocketAddress(hostname, amPort));
    srv.addInternalEndpoint(rpcEndpoint);
    Endpoint pluginEndpoint = null;
    if (pluginPort >= 0) {
        pluginEndpoint = RegistryTypeUtils.ipcEndpoint(IPC_PLUGIN, new InetSocketAddress(hostname, pluginPort));
        srv.addInternalEndpoint(pluginEndpoint);
    }
    srv.set(AM_SESSION_ID, sessionId);
    boolean hasToken = serializedToken != null;
    srv.set(AM_PLUGIN_TOKEN, hasToken ? serializedToken : "");
    srv.set(AM_PLUGIN_JOBID, jobIdForToken != null ? jobIdForToken : "");
    srv.set(AM_GUARANTEED_COUNT, Integer.toString(guaranteedCount));
    String uniqueId = registerServiceRecord(srv);
    LOG.info("Registered this AM: rpc: {}, plugin: {}, sessionId: {}, token: {}, znodePath: {}", rpcEndpoint, pluginEndpoint, sessionId, hasToken, getRegistrationZnodePath());
    return uniqueId;
}
Also used : Endpoint(org.apache.hadoop.registry.client.types.Endpoint) InetSocketAddress(java.net.InetSocketAddress) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord)

Example 42 with ServiceRecord

use of org.apache.hadoop.registry.client.types.ServiceRecord in project hive by apache.

the class ZkRegistryBase method populateCache.

protected final void populateCache(PathChildrenCache instancesCache, boolean doInvokeListeners) {
    for (ChildData childData : instancesCache.getCurrentData()) {
        byte[] data = getWorkerData(childData, workerNodePrefix);
        if (data == null)
            continue;
        String nodeName = extractNodeName(childData);
        if (!nodeName.startsWith(workerNodePrefix))
            continue;
        int ephSeqVersion = extractSeqNum(nodeName);
        try {
            ServiceRecord srv = encoder.fromBytes(childData.getPath(), data);
            InstanceType instance = createServiceInstance(srv);
            addToCache(childData.getPath(), instance.getHost(), instance);
            if (doInvokeListeners) {
                for (ServiceInstanceStateChangeListener<InstanceType> listener : stateChangeListeners) {
                    listener.onCreate(instance, ephSeqVersion);
                }
            }
        } catch (IOException e) {
            LOG.error("Unable to decode data for zkpath: {}." + " Ignoring from current instances list..", childData.getPath());
        }
    }
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) IOException(java.io.IOException) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord)

Aggregations

ServiceRecord (org.apache.hadoop.registry.client.types.ServiceRecord)42 Test (org.junit.Test)21 AbstractRegistryTest (org.apache.hadoop.registry.AbstractRegistryTest)14 IOException (java.io.IOException)10 RegistryPathStatus (org.apache.hadoop.registry.client.types.RegistryPathStatus)6 NoRecordException (org.apache.hadoop.registry.client.exceptions.NoRecordException)5 Endpoint (org.apache.hadoop.registry.client.types.Endpoint)5 HashMap (java.util.HashMap)4 ParseException (org.apache.commons.cli.ParseException)4 PathNotFoundException (org.apache.hadoop.fs.PathNotFoundException)4 RegistryTypeUtils.inetAddrEndpoint (org.apache.hadoop.registry.client.binding.RegistryTypeUtils.inetAddrEndpoint)4 RegistryTypeUtils.restEndpoint (org.apache.hadoop.registry.client.binding.RegistryTypeUtils.restEndpoint)4 InvalidRecordException (org.apache.hadoop.registry.client.exceptions.InvalidRecordException)4 URISyntaxException (java.net.URISyntaxException)3 Map (java.util.Map)3 PathIsNotEmptyDirectoryException (org.apache.hadoop.fs.PathIsNotEmptyDirectoryException)3 ZKPathDumper (org.apache.hadoop.registry.client.impl.zk.ZKPathDumper)3 EOFException (java.io.EOFException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 URI (java.net.URI)2