Search in sources :

Example 21 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeImageServerService method getComputeImageServer.

/**
 * Show compute image server attributes.
 *
 * @param id
 *            the URN of compute image server
 * @brief Show compute image server
 * @return Compute image server details
 */
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ComputeImageServerRestRep getComputeImageServer(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, ComputeImageServer.class, "id");
    ComputeImageServer imageServer = queryResource(id);
    return map(_dbClient, imageServer);
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 22 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeImageServerService method deleteComputeImageServer.

/**
 * Delete the Compute image server
 *
 * @param id
 *            the URN of compute image server
 *
 * @brief Delete an image server
 * @return {@link Response} instance
 */
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response deleteComputeImageServer(@PathParam("id") URI id) {
    // Validate the imageServer
    log.info("Delete computeImageServer id {} ", id);
    ArgValidator.checkFieldUriType(id, ComputeImageServer.class, "id");
    ComputeImageServer imageServer = _dbClient.queryObject(ComputeImageServer.class, id);
    ArgValidator.checkEntityNotNull(imageServer, id, isIdEmbeddedInURL(id));
    // make sure there are no active jobs associated with this imageserver
    checkActiveJobsForImageServer(id);
    // Remove the association with the ComputeSystem and then delete the
    // imageServer
    List<URI> imageServerURIList = _dbClient.queryByType(ComputeImageServer.class, true);
    ArrayList<URI> tempList = Lists.newArrayList(imageServerURIList.iterator());
    if (tempList.size() > 1) {
        removeImageServerFromComputeSystem(id);
    } else if (tempList.size() == 1) {
        // If the imageServer being deleted is the last one,
        // then check if there are any valid AVAILABLE images, if so
        // throw exception because user cannot delete all imageServers when
        // there are valid images available.
        boolean hasValidImages = false;
        List<URI> imageURIList = _dbClient.queryByType(ComputeImage.class, true);
        Iterator<ComputeImage> imageItr = _dbClient.queryIterativeObjects(ComputeImage.class, imageURIList);
        while (imageItr.hasNext()) {
            ComputeImage computeImage = (ComputeImage) imageItr.next();
            if (ComputeImageStatus.AVAILABLE.name().equals(computeImage.getComputeImageStatus())) {
                hasValidImages = true;
                break;
            }
        }
        if (hasValidImages) {
            throw APIException.badRequests.cannotDeleteImageServer();
        } else {
            removeImageServerFromComputeSystem(id);
        }
    }
    // Set to inactive.
    _dbClient.markForDeletion(imageServer);
    auditOp(OperationTypeEnum.DELETE_COMPUTE_IMAGESERVER, true, null, imageServer.getId().toString(), imageServer.getImageServerIp(), imageServer.getImageServerUser());
    return Response.ok().build();
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Iterator(java.util.Iterator) ComputeImageServerList(com.emc.storageos.model.compute.ComputeImageServerList) List(java.util.List) ArrayList(java.util.ArrayList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URI(java.net.URI) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 23 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeImageService method getComputeImage.

/**
 * Show compute image attribute.
 *
 * @param id
 *            the URN of compute image
 * @brief Show compute image
 * @return Compute image details
 */
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ComputeImageRestRep getComputeImage(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, ComputeImage.class, "id");
    ComputeImage ci = queryResource(id);
    List<ComputeImageServer> successfulServers = new ArrayList<ComputeImageServer>();
    List<ComputeImageServer> failedServers = new ArrayList<ComputeImageServer>();
    getImageImportStatus(ci, successfulServers, failedServers);
    return ComputeMapper.map(ci, successfulServers, failedServers);
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) ArrayList(java.util.ArrayList) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeImageService method deleteImageFromImageServers.

/**
 * Delete any image references or associations from all existing ImageServers.
 * @param ci {@link ComputeImage}
 */
private void deleteImageFromImageServers(ComputeImage ci) {
    List<URI> ids = _dbClient.queryByType(ComputeImageServer.class, true);
    for (URI imageServerId : ids) {
        ComputeImageServer imageServer = _dbClient.queryObject(ComputeImageServer.class, imageServerId);
        if (imageServer.getFailedComputeImages() != null && imageServer.getFailedComputeImages().contains(ci.getId().toString())) {
            imageServer.getFailedComputeImages().remove(ci.getId().toString());
        } else if (imageServer.getComputeImages() != null && imageServer.getComputeImages().contains(ci.getId().toString())) {
            imageServer.getComputeImages().remove(ci.getId().toString());
        }
        _dbClient.updateObject(imageServer);
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) URI(java.net.URI)

Example 25 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeSystemService method associateImageServerToComputeSystem.

/**
 * Associate's a given imageServer URI to the computeSystem.
 * @param imageServerURI
 * @param cs
 */
private void associateImageServerToComputeSystem(URI imageServerURI, ComputeSystem cs) {
    if (!NullColumnValueGetter.isNullURI(imageServerURI)) {
        ComputeImageServer imageServer = _dbClient.queryObject(ComputeImageServer.class, imageServerURI);
        if (imageServer != null) {
            cs.setComputeImageServer(imageServerURI);
        } else {
            throw APIException.badRequests.invalidParameter("compute image server", imageServerURI.toString());
        }
    } else {
        List<URI> imageServerURIList = _dbClient.queryByType(ComputeImageServer.class, true);
        ArrayList<URI> tempList = Lists.newArrayList(imageServerURIList.iterator());
        if (tempList.size() == 1) {
            Iterator<ComputeImageServer> imageServerItr = _dbClient.queryIterativeObjects(ComputeImageServer.class, tempList);
            while (imageServerItr.hasNext()) {
                ComputeImageServer imageSvr = imageServerItr.next();
                if (imageSvr != null && imageSvr.getComputeImageServerStatus().equals(ComputeImageServerStatus.AVAILABLE.toString())) {
                    _log.info("Automatically associating compute System {} with available image Server {}.", cs.getLabel(), imageSvr.getLabel());
                    cs.setComputeImageServer(imageSvr.getId());
                }
            }
        } else {
            // Compute system can live without an image server, such as bare metal.
            cs.setComputeImageServer(NullColumnValueGetter.getNullURI());
        }
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) URI(java.net.URI)

Aggregations

ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)26 URI (java.net.URI)13 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)9 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 MalformedURLException (java.net.MalformedURLException)9 ComputeImage (com.emc.storageos.db.client.model.ComputeImage)8 Produces (javax.ws.rs.Produces)6 SSHSession (com.emc.storageos.networkcontroller.SSHSession)5 ArrayList (java.util.ArrayList)5 ComputeImageJob (com.emc.storageos.db.client.model.ComputeImageJob)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)4 Workflow (com.emc.storageos.workflow.Workflow)4 Path (javax.ws.rs.Path)4 StringSet (com.emc.storageos.db.client.model.StringSet)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3