Search in sources :

Example 1 with DeploymentId

use of org.apache.hyracks.api.deployment.DeploymentId in project asterixdb by apache.

the class HyracksConnection method deployBinary.

@Override
public DeploymentId deployBinary(List<String> jars) throws Exception {
    /** generate a deployment id */
    DeploymentId deploymentId = new DeploymentId(UUID.randomUUID().toString());
    List<URL> binaryURLs = new ArrayList<>();
    if (jars != null && !jars.isEmpty()) {
        CloseableHttpClient hc = new DefaultHttpClient();
        try {
            /** upload jars through a http client one-by-one to the CC server */
            for (String jar : jars) {
                int slashIndex = jar.lastIndexOf('/');
                String fileName = jar.substring(slashIndex + 1);
                String url = "http://" + ccHost + ":" + ccInfo.getWebPort() + "/applications/" + deploymentId.toString() + "&" + fileName;
                HttpPut put = new HttpPut(url);
                put.setEntity(new FileEntity(new File(jar), "application/octet-stream"));
                HttpResponse response = hc.execute(put);
                response.getEntity().consumeContent();
                if (response.getStatusLine().getStatusCode() != 200) {
                    hci.unDeployBinary(deploymentId);
                    throw new HyracksException(response.getStatusLine().toString());
                }
                /** add the uploaded URL address into the URLs of jars to be deployed at NCs */
                binaryURLs.add(new URL(url));
            }
        } finally {
            hc.close();
        }
    }
    /** deploy the URLs to the CC and NCs */
    hci.deployBinary(binaryURLs, deploymentId);
    return deploymentId;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) DeploymentId(org.apache.hyracks.api.deployment.DeploymentId) FileEntity(org.apache.http.entity.FileEntity) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) URL(java.net.URL) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpPut(org.apache.http.client.methods.HttpPut) File(java.io.File)

Example 2 with DeploymentId

use of org.apache.hyracks.api.deployment.DeploymentId in project asterixdb by apache.

the class CliDeployBinaryWork method doRun.

@Override
public void doRun() {
    try {
        if (deploymentId == null) {
            deploymentId = new DeploymentId(UUID.randomUUID().toString());
        }
        /**
             * Deploy for the cluster controller
             */
        DeploymentUtils.deploy(deploymentId, binaryURLs, ccs.getContext().getJobSerializerDeserializerContainer(), ccs.getServerContext(), false);
        /**
             * Deploy for the node controllers
             */
        INodeManager nodeManager = ccs.getNodeManager();
        Collection<String> nodeIds = nodeManager.getAllNodeIds();
        final DeploymentRun dRun = new DeploymentRun(nodeIds);
        /** The following call prevents a user to deploy with the same deployment id simultaneously. */
        ccs.addDeploymentRun(deploymentId, dRun);
        /***
             * deploy binaries to each node controller
             */
        for (NodeControllerState ncs : nodeManager.getAllNodeControllerStates()) {
            ncs.getNodeController().deployBinary(deploymentId, binaryURLs);
        }
        ccs.getExecutor().execute(new Runnable() {

            @Override
            public void run() {
                try {
                    /**
                         * wait for completion
                         */
                    dRun.waitForCompletion();
                    ccs.removeDeploymentRun(deploymentId);
                    callback.setValue(deploymentId);
                } catch (Exception e) {
                    callback.setException(e);
                }
            }
        });
    } catch (Exception e) {
        callback.setException(e);
    }
}
Also used : INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) DeploymentId(org.apache.hyracks.api.deployment.DeploymentId) DeploymentRun(org.apache.hyracks.control.common.deployment.DeploymentRun) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState)

Example 3 with DeploymentId

use of org.apache.hyracks.api.deployment.DeploymentId in project asterixdb by apache.

the class CliUnDeployBinaryWork method doRun.

@Override
public void doRun() {
    try {
        if (deploymentId == null) {
            deploymentId = new DeploymentId(UUID.randomUUID().toString());
        }
        /**
             * Deploy for the cluster controller
             */
        DeploymentUtils.undeploy(deploymentId, ccs.getContext().getJobSerializerDeserializerContainer(), ccs.getServerContext());
        /**
             * Deploy for the node controllers
             */
        INodeManager nodeManager = ccs.getNodeManager();
        Collection<String> nodeIds = nodeManager.getAllNodeIds();
        final DeploymentRun dRun = new DeploymentRun(nodeIds);
        /** The following call prevents a user to undeploy with the same deployment id simultaneously. */
        ccs.addDeploymentRun(deploymentId, dRun);
        /***
             * deploy binaries to each node controller
             */
        for (NodeControllerState ncs : nodeManager.getAllNodeControllerStates()) {
            ncs.getNodeController().undeployBinary(deploymentId);
        }
        ccs.getExecutor().execute(new Runnable() {

            @Override
            public void run() {
                try {
                    /**
                         * wait for completion
                         */
                    dRun.waitForCompletion();
                    ccs.removeDeploymentRun(deploymentId);
                    callback.setValue(null);
                } catch (Exception e) {
                    callback.setException(e);
                }
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) DeploymentId(org.apache.hyracks.api.deployment.DeploymentId) DeploymentRun(org.apache.hyracks.control.common.deployment.DeploymentRun) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState)

Example 4 with DeploymentId

use of org.apache.hyracks.api.deployment.DeploymentId in project asterixdb by apache.

the class JobExecutor method startTasks.

private void startTasks(Map<String, List<TaskAttemptDescriptor>> taskAttemptMap) throws HyracksException {
    final DeploymentId deploymentId = jobRun.getDeploymentId();
    final JobId jobId = jobRun.getJobId();
    final ActivityClusterGraph acg = jobRun.getActivityClusterGraph();
    final Map<ConnectorDescriptorId, IConnectorPolicy> connectorPolicies = new HashMap<>(jobRun.getConnectorPolicyMap());
    INodeManager nodeManager = ccs.getNodeManager();
    try {
        byte[] acgBytes = predistributed ? null : JavaSerializationUtils.serialize(acg);
        for (Map.Entry<String, List<TaskAttemptDescriptor>> entry : taskAttemptMap.entrySet()) {
            String nodeId = entry.getKey();
            final List<TaskAttemptDescriptor> taskDescriptors = entry.getValue();
            final NodeControllerState node = nodeManager.getNodeControllerState(nodeId);
            if (node != null) {
                node.getActiveJobIds().add(jobRun.getJobId());
                boolean changed = jobRun.getParticipatingNodeIds().add(nodeId);
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine("Starting: " + taskDescriptors + " at " + entry.getKey());
                }
                byte[] jagBytes = changed ? acgBytes : null;
                node.getNodeController().startTasks(deploymentId, jobId, jagBytes, taskDescriptors, connectorPolicies, jobRun.getFlags());
            }
        }
    } catch (Exception e) {
        throw new HyracksException(e);
    }
}
Also used : INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) DeploymentId(org.apache.hyracks.api.deployment.DeploymentId) HashMap(java.util.HashMap) IConnectorPolicy(org.apache.hyracks.api.dataflow.connectors.IConnectorPolicy) ConnectorDescriptorId(org.apache.hyracks.api.dataflow.ConnectorDescriptorId) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) TaskAttemptDescriptor(org.apache.hyracks.control.common.job.TaskAttemptDescriptor) ActivityClusterGraph(org.apache.hyracks.api.job.ActivityClusterGraph) ArrayList(java.util.ArrayList) List(java.util.List) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState) HashMap(java.util.HashMap) Map(java.util.Map) JobId(org.apache.hyracks.api.job.JobId)

Aggregations

DeploymentId (org.apache.hyracks.api.deployment.DeploymentId)4 NodeControllerState (org.apache.hyracks.control.cc.NodeControllerState)3 INodeManager (org.apache.hyracks.control.cc.cluster.INodeManager)3 ArrayList (java.util.ArrayList)2 HyracksException (org.apache.hyracks.api.exceptions.HyracksException)2 DeploymentRun (org.apache.hyracks.control.common.deployment.DeploymentRun)2 File (java.io.File)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 HttpResponse (org.apache.http.HttpResponse)1 HttpPut (org.apache.http.client.methods.HttpPut)1 FileEntity (org.apache.http.entity.FileEntity)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 ConnectorDescriptorId (org.apache.hyracks.api.dataflow.ConnectorDescriptorId)1 IConnectorPolicy (org.apache.hyracks.api.dataflow.connectors.IConnectorPolicy)1 ActivityClusterGraph (org.apache.hyracks.api.job.ActivityClusterGraph)1 JobId (org.apache.hyracks.api.job.JobId)1