use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.
the class ComputeUtils method createHosts.
/**
* Creates tasks to provision specified hosts to the given cluster.
* @param Cluster
* @param URI of computeVirtualPool to pick blades from
* @param List of hostNames
* @param URI of varray
* @return list of successfully created hosts
*/
public static List<Host> createHosts(Cluster cluster, URI vcp, List<String> hostNamesIn, URI varray) throws Exception {
// new hosts will be created with lower case hostNames. force it here so we can find host afterwards
List<String> hostNames = Lists.newArrayList();
for (String hostNameIn : hostNamesIn) {
hostNames.add(hostNameIn != null ? hostNameIn.toLowerCase() : null);
}
List<Host> createdHosts = new ArrayList<>();
Tasks<HostRestRep> tasks = null;
try {
tasks = execute(new CreateHosts(vcp, cluster.getId(), hostNames, varray));
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.createhosts.failure", hostNames, e.getMessage());
}
// Some tasks could succeed while others could error out.
Map<URI, String> hostDeactivateMap = new HashMap<URI, String>();
if ((tasks != null) && (tasks.getTasks() != null)) {
List<Task<HostRestRep>> tasklist = tasks.getTasks();
List<Task<HostRestRep>> oritasklist = tasks.getTasks();
while (!tasklist.isEmpty()) {
tasklist = waitAndRefresh(tasklist);
for (Task<HostRestRep> successfulTask : getSuccessfulTasks(tasklist)) {
URI hostUri = successfulTask.getResourceId();
addAffectedResource(hostUri);
Host host = execute(new GetHost(hostUri));
createdHosts.add(host);
tasklist.remove(successfulTask);
oritasklist.remove(successfulTask);
}
for (Task<HostRestRep> failedTask : getFailedTasks(tasklist)) {
ExecutionUtils.currentContext().logError("computeutils.createhosts.failure.task", failedTask.getResource().getName(), failedTask.getMessage());
hostDeactivateMap.put(failedTask.getResourceId(), failedTask.getResource().getName());
tasklist.remove(failedTask);
oritasklist.remove(failedTask);
}
}
for (Task<HostRestRep> hostToRemove : oritasklist) {
hostDeactivateMap.put(hostToRemove.getResourceId(), hostToRemove.getResource().getName());
}
} else {
ExecutionUtils.currentContext().logError("computeutils.createhosts.noTasks,created", hostNames);
}
// Deactivate hosts that failed in the create step
if (MapUtils.isNotEmpty(hostDeactivateMap)) {
deactivateHostURIs(hostDeactivateMap);
}
return createdHosts;
}
use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.
the class CreateFileSnapshotService method execute.
@Override
public void execute() {
for (FileShareRestRep fs : fileSystems) {
String fileSystemId = fs.getId().toString();
checkAndPurgeObsoleteSnapshot(fileSystemId);
Task<FileSnapshotRestRep> task = ViPRExecutionUtils.execute(new CreateFileSnapshot(fileSystemId, name));
addAffectedResource(task);
// record file snapshots for retention
List<Task<FileSnapshotRestRep>> tasks = new ArrayList<Task<FileSnapshotRestRep>>();
tasks.add(task);
addRetainedReplicas(fs.getId(), tasks);
}
}
use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.
the class ObjectBuckets method create.
/**
* Begins create the bucket.
* <p>
* API Call: <tt>POST /object/buckets</tt>
*
* @param input
* the create configuration.
* @return a task for monitoring the progress of the operation.
*/
public Task<BucketRestRep> create(BucketParam input, URI project) {
URI uri = client.uriBuilder(baseUrl).queryParam("project", project).build();
TaskResourceRep task = client.postURI(TaskResourceRep.class, input, uri);
return new Task<>(client, task, resourceClass);
}
use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.
the class Tenants method createHost.
public Task<HostRestRep> createHost(URI tenantId, HostCreateParam input, boolean validateConnection) {
UriBuilder uriBuilder = client.uriBuilder(HOST_BY_TENANT_URL);
if (validateConnection) {
uriBuilder.queryParam(VALIDATE_CONNECTION_PARAM, Boolean.TRUE);
}
TaskResourceRep task = client.postURI(TaskResourceRep.class, input, uriBuilder.build(tenantId));
return new Task<HostRestRep>(client, task, HostRestRep.class);
}
use of com.emc.vipr.client.Task in project coprhd-controller by CoprHD.
the class ComputeUtils method makeBootVolumes.
/**
* Attempts to create a boot volume for each host sent in.
* Guarantees a map with all hosts, even if that host's boot volume creation failed.
*
* @param project project
* @param virtualArray virtual array
* @param virtualPool virtual pool
* @param size size of boot volumes
* @param hosts host list
* @param client NB API
* @param URI portGroup
* @return map of host objects to volume IDs. (volume ID is null if that host didn't get a good boot volume)
*/
public static Map<Host, URI> makeBootVolumes(URI project, URI virtualArray, URI virtualPool, Double size, List<Host> hosts, ViPRCoreClient client, URI portGroup) {
Map<String, Host> volumeNameToHostMap = new HashMap<>();
Map<Host, URI> hostToBootVolumeIdMap = new HashMap<>();
if (hosts == null || hosts.isEmpty()) {
return Maps.newHashMap();
}
List<Task<VolumeRestRep>> tasks = new ArrayList<>();
ArrayList<String> volumeNames = new ArrayList<>();
for (Host host : hosts) {
if (host == null) {
volumeNames.add(null);
continue;
}
String volumeName = host.getHostName().replaceAll("[^A-Za-z0-9_]", "_").concat("_boot");
while (!BlockStorageUtils.getVolumeByName(volumeName).isEmpty()) {
// vol name used?
if (volumeName.matches(".*_\\d+$")) {
// incr suffix number
int volNumber = Integer.parseInt(volumeName.substring(volumeName.lastIndexOf("_") + 1));
volumeName = volumeName.replaceAll("_\\d+$", "_" + ++volNumber);
} else {
// add suffix number
volumeName = volumeName.concat("_0");
}
}
try {
tasks.add(BlockStorageUtils.createVolumesByName(project, virtualArray, virtualPool, size, nullConsistencyGroup, volumeName, portGroup, // does not wait for task
host.getId()));
volumeNameToHostMap.put(volumeName, host);
} catch (ExecutionException e) {
String errorMessage = e.getMessage() == null ? "" : e.getMessage();
ExecutionUtils.currentContext().logError("computeutils.makebootvolumes.failure", host.getHostName(), errorMessage);
}
}
// monitor tasks
List<URI> bootVolsToRemove = new ArrayList<URI>();
while (!tasks.isEmpty()) {
tasks = waitAndRefresh(tasks);
for (Task<VolumeRestRep> successfulTask : getSuccessfulTasks(tasks)) {
URI volumeId = successfulTask.getResourceId();
String volumeName = successfulTask.getResource().getName();
Host tempHost = volumeNameToHostMap.get(volumeName);
tempHost.setBootVolumeId(volumeId);
addAffectedResource(volumeId);
tasks.remove(successfulTask);
addBootVolumeTag(volumeId, tempHost.getId());
BlockObjectRestRep volume = BlockStorageUtils.getBlockResource(volumeId);
if (BlockStorageUtils.isVolumeBootVolume(volume)) {
hostToBootVolumeIdMap.put(tempHost, volumeId);
} else {
bootVolsToRemove.add(volumeId);
tempHost.setBootVolumeId(NullColumnValueGetter.getNullURI());
hostToBootVolumeIdMap.put(tempHost, null);
}
}
for (Task<VolumeRestRep> failedTask : getFailedTasks(tasks)) {
String volumeName = failedTask.getResource().getName();
hostToBootVolumeIdMap.put(volumeNameToHostMap.get(volumeName), null);
String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
ExecutionUtils.currentContext().logError("computeutils.makebootvolumes.createvolume.failure", volumeName, errorMessage);
tasks.remove(failedTask);
}
}
if (!bootVolsToRemove.isEmpty()) {
try {
// No need to untag, this bootVolsToRemove list is based on volumes that never got the boot tag.
BlockStorageUtils.deactivateVolumes(bootVolsToRemove, VolumeDeleteTypeEnum.FULL);
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.bootvolume.deactivate.failure", e.getMessage());
}
}
return hostToBootVolumeIdMap;
}
Aggregations