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