use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class DbClientGeoTest method testEncryption.
@Test
public void testEncryption() {
DbClient dbClient = getDbClient();
// create a geo-replicated object with an encrypted field
AuthnProvider authProvider = new AuthnProvider();
authProvider.setId(URIUtil.createId(AuthnProvider.class));
authProvider.setManagerPassword("password");
dbClient.createObject(authProvider);
// create a local object with an encrypted field
Vcenter vc = new Vcenter();
vc.setId(URIUtil.createId(Vcenter.class));
vc.setPassword("password");
dbClient.createObject(vc);
AuthnProvider q0 = dbClient.queryObject(AuthnProvider.class, authProvider.getId());
Assert.assertNotNull(q0);
Assert.assertEquals(q0.getManagerPassword(), "password");
Vcenter k0 = dbClient.queryObject(Vcenter.class, vc.getId());
Assert.assertNotNull(k0);
Assert.assertEquals(k0.getPassword(), "password");
// null out geo encryption provider; make sure local object is still valid
TypeMap.setEncryptionProviders(_encryptionProvider, null);
Vcenter k1 = dbClient.queryObject(Vcenter.class, vc.getId());
Assert.assertNotNull(k1);
Assert.assertEquals(k1.getPassword(), "password");
// geo-replicated object should be encrypted
AuthnProvider q1 = dbClient.queryObject(AuthnProvider.class, authProvider.getId());
Assert.assertNotNull(q1);
Assert.assertFalse(q1.getManagerPassword().equals("password"));
// restore geo encryption provider and null out local
TypeMap.setEncryptionProviders(null, _geoEncryptionProvider);
AuthnProvider q2 = dbClient.queryObject(AuthnProvider.class, authProvider.getId());
Assert.assertNotNull(q2);
Assert.assertEquals(q2.getManagerPassword(), "password");
Vcenter k2 = dbClient.queryObject(Vcenter.class, vc.getId());
Assert.assertNotNull(k2);
Assert.assertFalse(k2.getPassword().equals("password"));
// now just to make sure the encryption keys are different, lets swap them
// and make sure the queries are not successful
TypeMap.setEncryptionProviders(_geoEncryptionProvider, _encryptionProvider);
try {
AuthnProvider q3 = dbClient.queryObject(AuthnProvider.class, authProvider.getId());
Assert.fail("geo repliated object query after swapping encryption providers succeeded; failure expected");
} catch (Exception e) {
// this is expected; test passes
}
try {
Vcenter k3 = dbClient.queryObject(Vcenter.class, vc.getId());
Assert.fail("local object query after swapping encryption providers succeeded; failure expected");
} catch (Exception e) {
// this is expected; test passes
}
}
use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class ComputeUtils method validateBootVolumes.
/**
* Validate that the boot volume for this host is still on the server.
* This prevents us from deleting a re-purposed volume that was originally
* a boot volume.
*
* @return true if the volumes are valid, or the volumes are not able to be validated, so we can go ahead anyway.
*/
public static boolean validateBootVolumes(Cluster cluster, List<HostRestRep> hostsToValidate) {
// the references are fixed.
if (cluster == null || cluster.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.cluster");
return false;
}
// so return that the boot volume is valid due to lack of technical ability to dig any deeper.
if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noVcenterDataCenter", cluster.forDisplay());
return true;
}
VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
// until that's fixed.
if (dataCenter == null || dataCenter.getInactive() || NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.datacenter", cluster.forDisplay());
return false;
}
Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
// until that's fixed.
if (vcenter == null || vcenter.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.vcenter", cluster.forDisplay());
return false;
}
VMwareSupport vmware = null;
try {
vmware = new VMwareSupport();
vmware.connect(vcenter.getId());
for (HostRestRep clusterHost : hostsToValidate) {
Host host = BlockStorageUtils.getHost(clusterHost.getId());
// Do not validate a host no longer in our database
if (host == null || host.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", "N/A", "host not found or inactive");
return false;
}
// in the vCenter cluster, and therefore we can not perform a deep validation.
if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.vcenternotinhost", host.getHostName());
continue;
}
// any update to the host using the hostService automatically adds this association.
if (!NullColumnValueGetter.isNullURI(host.getVcenterDataCenter()) && host.getType() != null && host.getType().equalsIgnoreCase((Host.HostType.No_OS).name())) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.noOShost", host.getHostName());
continue;
}
// flag it as an issue.
if (clusterHost.getBootVolume() == null || NullColumnValueGetter.isNullURI(clusterHost.getBootVolume().getId())) {
ExecutionUtils.currentContext().logWarn("computeutils.removebootvolumes.failure.host", host.getHostName(), "no boot volume associated with host");
continue;
}
BlockObjectRestRep bootVolume = execute(new GetBlockResource(clusterHost.getBootVolume().getId()));
// Do not validate an old/non-existent boot volume representation
if (bootVolume == null || bootVolume.getInactive()) {
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.host", host.getHostName(), "boot volume not found or inactive");
return false;
}
HostSystem hostSystem = null;
try {
hostSystem = vmware.getHostSystem(dataCenter.getLabel(), clusterHost.getName(), false);
// we can't perform the validation.
if (hostSystem == null) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
continue;
}
HostSystemConnectionState connectionState = VMwareUtils.getConnectionState(hostSystem);
if (connectionState == null || connectionState == HostSystemConnectionState.notResponding || connectionState == HostSystemConnectionState.disconnected) {
String exMsg = "Validation of boot volume usage on host %s failed. " + "Validation failed because host is in a disconnected state or not responding state, and therefore cannot be validated. " + "Cannot decommission in current state. Recommended to either re-connect the host or remove the host from vCenter, " + "run vCenter discovery and address actionable events before attempting decommission of hosts in this cluster.";
// will print a boot volume re-purposed error message which is kind of misleading or incorrect reason for the failure.
throw new IllegalStateException(String.format(exMsg, host.getHostName()));
}
} catch (ExecutionException e) {
if (e.getCause() instanceof IllegalStateException) {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validation.skipped.hostnotinvcenter", host.getHostName());
continue;
}
// If it's anything other than the IllegalStateException, re-throw the base exception
throw e;
}
if (vmware.findScsiDisk(hostSystem, null, bootVolume, false, false) == null) {
// fail, host can't see its boot volume
ExecutionUtils.currentContext().logError("computeutils.removebootvolumes.failure.bootvolume", bootVolume.getDeviceLabel(), bootVolume.getWwn());
return false;
} else {
ExecutionUtils.currentContext().logInfo("computeutils.removebootvolumes.validated", host.getHostName(), bootVolume.getDeviceLabel());
}
}
} finally {
if (vmware != null) {
vmware.disconnect();
}
}
return true;
}
use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class CreateComputeClusterService method pushToVcenter.
private void pushToVcenter() {
if (vcenterId != null) {
boolean isVCenterUpdate = false;
List<ClusterRestRep> clusters = getClient().clusters().getByDataCenter(datacenterId);
for (ClusterRestRep resp : clusters) {
if (cluster.getLabel().equals(resp.getName())) {
isVCenterUpdate = true;
break;
}
}
try {
Vcenter vcenter = null;
VcenterDataCenter dataCenter = null;
vcenter = ComputeUtils.getVcenter(vcenterId);
if (null != datacenterId) {
dataCenter = ComputeUtils.getVcenterDataCenter(datacenterId);
}
boolean status = true;
if (isVCenterUpdate) {
logInfo("vcenter.cluster.update", cluster.getLabel());
if (dataCenter == null) {
status = ComputeUtils.updateVcenterCluster(cluster, datacenterId);
} else {
status = ComputeUtils.updateVcenterCluster(cluster, dataCenter);
}
if (!status) {
throw new IllegalStateException(ExecutionUtils.getMessage("vcenter.cluster.update.failed", cluster.getLabel()));
}
} else {
logInfo("compute.cluster.create.vcenter.cluster.datacenter", (vcenter != null ? vcenter.getLabel() : vcenterId), (dataCenter != null ? dataCenter.getLabel() : datacenterId));
if (dataCenter == null) {
status = ComputeUtils.createVcenterCluster(cluster, datacenterId);
} else {
status = ComputeUtils.createVcenterCluster(cluster, dataCenter);
}
if (!status) {
throw new IllegalStateException(ExecutionUtils.getMessage("vcenter.cluster.create.failed", cluster.getLabel()));
}
}
} catch (Exception e) {
logError("compute.cluster.vcenter.sync.failed.corrective.user.message", cluster.getLabel());
logError("compute.cluster.vcenter.push.failed", e.getMessage());
throw e;
}
}
}
use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method getVirtualMachines.
private List<String> getVirtualMachines(URI datacenterUri, URI clusterUri, boolean runningOnly) throws InternalException {
VcenterApiClient vcenterApiClient = null;
try {
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
_log.info("Request to get virtual machines for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
return runningOnly ? vcenterApiClient.getRunningVirtualMachines(vcenterDataCenter.getLabel(), cluster.getExternalId()) : vcenterApiClient.getVirtualMachines(vcenterDataCenter.getLabel(), cluster.getExternalId());
} catch (VcenterObjectNotFoundException e) {
throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
} catch (VcenterServerConnectionException e) {
throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
} catch (Exception e) {
_log.error("getVirtualMachines exception " + e);
throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method vcenterClusterRemoveHostOperation.
public void vcenterClusterRemoveHostOperation(URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI hostId, String stepId) {
VcenterApiClient vcenterApiClient = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterId);
Host host = _dbClient.queryObject(Host.class, hostId);
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
vcenterApiClient.removeHost(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName());
_log.info("Successfully removed host " + host.getHostName());
host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
_dbClient.updateObject(host);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception e) {
_log.error("vcenterClusterRemoveHostOperation exception ", e);
WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e));
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
Aggregations