Search in sources :

Example 11 with ComputeImage

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

the class ComputeMapper method map.

/**
 * Utility mapper method to map fields of {@link ComputeImageServer} columnFamily to {@link ComputeImageServerRestRep} rest
 * representation.
 *
 * @param dbclient
 *            {@link DbClient} instance
 * @param from
 *            {@link ComputeImageServer} instance that has to be mapped.
 * @return {@link ComputeImageServerRestRep}
 */
public static ComputeImageServerRestRep map(DbClient dbclient, ComputeImageServer from) {
    if (from == null) {
        return null;
    }
    ComputeImageServerRestRep to = new ComputeImageServerRestRep();
    mapDataObjectFields(from, to);
    try {
        to.setLink(new RestLinkRep("self", RestLinkFactory.simpleServiceLink(ResourceTypeEnum.COMPUTE_IMAGESERVER, from.getId())));
    } catch (URISyntaxException e) {
        LOG.warn("Error while creating self link URI.", e);
    }
    to.setImageServerIp(from.getImageServerIp());
    to.setImageServerSecondIp(from.getImageServerSecondIp());
    to.setTftpBootDir(from.getTftpBootDir());
    to.setComputeImageServerStatus(from.getComputeImageServerStatus());
    to.setImageServerUser(from.getImageServerUser());
    to.setOsInstallTimeout(new Long(TimeUnit.MILLISECONDS.toSeconds(from.getOsInstallTimeoutMs())).intValue());
    to.setSshTimeout(new Long(TimeUnit.MILLISECONDS.toSeconds(from.getSshTimeoutMs())).intValue());
    to.setImageImportTimeout(new Long(TimeUnit.MILLISECONDS.toSeconds(from.getImageImportTimeoutMs())).intValue());
    to.setComputeImages(new ArrayList<NamedRelatedResourceRep>());
    to.setFailedImages(new ArrayList<NamedRelatedResourceRep>());
    if (from.getComputeImages() != null) {
        for (String computeimage : from.getComputeImages()) {
            ComputeImage image = dbclient.queryObject(ComputeImage.class, URIUtil.uri(computeimage));
            if (image == null) {
                LOG.warn("Could not find compute image in database with id '" + computeimage + "'");
                continue;
            }
            to.getComputeImages().add(DbObjectMapper.toNamedRelatedResource(ResourceTypeEnum.COMPUTE_IMAGE, image.getId(), image.getLabel()));
        }
    }
    if (from.getFailedComputeImages() != null) {
        for (String failedImageID : from.getFailedComputeImages()) {
            ComputeImage failedImage = dbclient.queryObject(ComputeImage.class, URIUtil.uri(failedImageID));
            if (failedImage == null) {
                LOG.warn("Could not find failed compute image in database with id '" + failedImageID + "'");
                continue;
            }
            to.getFailedImages().add(DbObjectMapper.toNamedRelatedResource(ResourceTypeEnum.COMPUTE_IMAGE, failedImage.getId(), failedImage.getLabel()));
        }
    }
    return to;
}
Also used : RestLinkRep(com.emc.storageos.model.RestLinkRep) URISyntaxException(java.net.URISyntaxException) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) ComputeImageServerRestRep(com.emc.storageos.model.compute.ComputeImageServerRestRep) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 12 with ComputeImage

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

the class ComputeImageServerMigration method associateComputeImages.

private void associateComputeImages(ComputeImageServer imageServer) {
    boolean hasAvailableImages = false;
    List<URI> computeImageURIs = dbClient.queryByType(ComputeImage.class, true);
    Iterator<ComputeImage> computeImageListIterator = dbClient.queryIterativeObjects(ComputeImage.class, computeImageURIs);
    while (computeImageListIterator.hasNext()) {
        ComputeImage computeImage = computeImageListIterator.next();
        if (computeImage.getComputeImageStatus().equals(ComputeImageStatus.NOT_AVAILABLE.name())) {
            if (imageServer.getFailedComputeImages() == null) {
                imageServer.setFailedComputeImages(new StringSet());
            }
            imageServer.getFailedComputeImages().add(computeImage.getId().toString());
        } else if (computeImage.getComputeImageStatus().equals(ComputeImageStatus.AVAILABLE.name())) {
            if (imageServer.getComputeImages() == null) {
                imageServer.setComputeImages(new StringSet());
            }
            imageServer.getComputeImages().add(computeImage.getId().toString());
            hasAvailableImages = true;
        }
    }
    if (hasAvailableImages) {
        imageServer.setComputeImageServerStatus(ComputeImageServer.ComputeImageServerStatus.AVAILABLE.name());
    } else {
        imageServer.setComputeImageServerStatus(ComputeImageServer.ComputeImageServerStatus.NOT_AVAILABLE.name());
    }
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 13 with ComputeImage

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

the class ComputeImageMigrationTest method prepareData.

@Override
protected void prepareData() throws Exception {
    DbClient dbClient = getDbClient();
    ComputeImage image1 = new ComputeImage();
    image1.setId(URIUtil.createId(ComputeImage.class));
    image1.setLabel(IMAGE_NAME_WITH_PWD);
    image1.setImageUrl(urlWithPwd);
    dbClient.createObject(image1);
    ComputeImage image2 = new ComputeImage();
    image2.setId(URIUtil.createId(ComputeImage.class));
    image2.setLabel(IMAGE_NAME_WITHOUT_PWD);
    image2.setImageUrl(urlWithoutPwd);
    dbClient.createObject(image2);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 14 with ComputeImage

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

the class ComputeImageMigrationTest method verifyResults.

@Override
protected void verifyResults() throws Exception {
    DbClient dbClient = getDbClient();
    List<URI> imageUris = dbClient.queryByType(ComputeImage.class, true);
    Iterator<ComputeImage> imageItr = dbClient.queryIterativeObjects(ComputeImage.class, imageUris);
    while (imageItr.hasNext()) {
        ComputeImage image = imageItr.next();
        if (image.getLabel().equalsIgnoreCase(IMAGE_NAME_WITH_PWD)) {
            Assert.assertNotEquals(image.getImageUrl(), urlWithPwd);
        } else if (image.getLabel().equalsIgnoreCase(IMAGE_NAME_WITHOUT_PWD)) {
            Assert.assertEquals(image.getImageUrl(), urlWithoutPwd);
        }
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) URI(java.net.URI) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 15 with ComputeImage

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

the class ComputeImageMigration method process.

@Override
public void process() throws MigrationCallbackException {
    log.info("Starting Compute Image Migration");
    if (null == encryptionProvider) {
        EncryptionProviderImpl encryptionProviderImpl = new EncryptionProviderImpl();
        encryptionProviderImpl.setCoordinator(coordinatorClient);
        encryptionProviderImpl.start();
        encryptionProvider = encryptionProviderImpl;
    }
    List<URI> computeImageURIList = dbClient.queryByType(ComputeImage.class, true);
    Iterator<ComputeImage> computeImageItr = dbClient.queryIterativeObjects(ComputeImage.class, computeImageURIList, true);
    while (computeImageItr.hasNext()) {
        ComputeImage image = computeImageItr.next();
        String imageUrl = image.getImageUrl();
        String password = extractPasswordFromImageUrl(imageUrl);
        String encryptedPassword = password;
        if (StringUtils.isNotBlank(password)) {
            encryptedPassword = encryptionProvider.getEncryptedString(password);
            imageUrl = StringUtils.replace(imageUrl, ":" + password + "@", ":" + encryptedPassword + "@");
        }
        image.setImageUrl(imageUrl);
        dbClient.updateObject(image);
        log.info("Successfully migrated compute image : {} - {}", image.getLabel(), image.getId());
    }
    log.info("Completed Compute Image Migration");
}
Also used : EncryptionProviderImpl(com.emc.storageos.db.client.impl.EncryptionProviderImpl) URI(java.net.URI) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Aggregations

ComputeImage (com.emc.storageos.db.client.model.ComputeImage)22 URI (java.net.URI)10 ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)8 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 Produces (javax.ws.rs.Produces)7 ComputeImageJob (com.emc.storageos.db.client.model.ComputeImageJob)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 MalformedURLException (java.net.MalformedURLException)6 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 SSHSession (com.emc.storageos.networkcontroller.SSHSession)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 Host (com.emc.storageos.db.client.model.Host)3 POST (javax.ws.rs.POST)3 DbClient (com.emc.storageos.db.client.DbClient)2 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)2 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)2