Search in sources :

Example 6 with Task

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;
}
Also used : Task(com.emc.vipr.client.Task) HashMap(java.util.HashMap) GetHost(com.emc.sa.service.vipr.tasks.GetHost) ArrayList(java.util.ArrayList) GetHost(com.emc.sa.service.vipr.tasks.GetHost) DiscoverHost(com.emc.sa.service.vipr.compute.tasks.DiscoverHost) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) TimeoutException(com.emc.vipr.client.exceptions.TimeoutException) ExecutionException(com.emc.sa.engine.ExecutionException) ViPRException(com.emc.vipr.client.exceptions.ViPRException) HostRestRep(com.emc.storageos.model.host.HostRestRep) CreateHosts(com.emc.sa.service.vipr.compute.tasks.CreateHosts)

Example 7 with Task

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);
    }
}
Also used : Task(com.emc.vipr.client.Task) FileSnapshotRestRep(com.emc.storageos.model.file.FileSnapshotRestRep) ArrayList(java.util.ArrayList) CreateFileSnapshot(com.emc.sa.service.vipr.file.tasks.CreateFileSnapshot) FileShareRestRep(com.emc.storageos.model.file.FileShareRestRep)

Example 8 with Task

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);
}
Also used : Task(com.emc.vipr.client.Task) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI)

Example 9 with Task

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);
}
Also used : Task(com.emc.vipr.client.Task) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 10 with Task

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;
}
Also used : Task(com.emc.vipr.client.Task) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GetHost(com.emc.sa.service.vipr.tasks.GetHost) DiscoverHost(com.emc.sa.service.vipr.compute.tasks.DiscoverHost) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) TimeoutException(com.emc.vipr.client.exceptions.TimeoutException) ExecutionException(com.emc.sa.engine.ExecutionException) ViPRException(com.emc.vipr.client.exceptions.ViPRException) ExecutionException(com.emc.sa.engine.ExecutionException) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep)

Aggregations

Task (com.emc.vipr.client.Task)21 URI (java.net.URI)13 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)11 ArrayList (java.util.ArrayList)6 ExecutionException (com.emc.sa.engine.ExecutionException)5 DeactivateHost (com.emc.sa.service.vipr.compute.tasks.DeactivateHost)5 DiscoverHost (com.emc.sa.service.vipr.compute.tasks.DiscoverHost)5 GetHost (com.emc.sa.service.vipr.tasks.GetHost)5 Host (com.emc.storageos.db.client.model.Host)5 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)4 FileShareRestRep (com.emc.storageos.model.file.FileShareRestRep)4 TimeoutException (com.emc.vipr.client.exceptions.TimeoutException)4 ViPRException (com.emc.vipr.client.exceptions.ViPRException)4 ViPRHttpException (com.emc.vipr.client.exceptions.ViPRHttpException)4 HashMap (java.util.HashMap)4 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)3 FileSnapshotRestRep (com.emc.storageos.model.file.FileSnapshotRestRep)3 HostRestRep (com.emc.storageos.model.host.HostRestRep)3 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)2 ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)2