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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations