use of com.vmware.vim25.mo.Datacenter in project coprhd-controller by CoprHD.
the class ComputeUtils method verifyClusterInVcenter.
/**
* Precheck to verify if cluster is associated to a datacenter and if it still
* on the same datacenter and vcenter. Precheck fails the order if the cluster
* has datacenter association and is not found on the vcenter under the same datacenter
* Precheck also fails if the cluster found by name in vcenter does not match externalId
* in ViPR Cluster.
* If cluster does not have a datacenter association, then the cluster is
* a vipr cluster and precheck passes.
* @param cluster {@link Cluster} cluster instance
* @param preCheckErrors {@link StringBuilder} instance
* @return preCheckErrors
*/
public static StringBuilder verifyClusterInVcenter(Cluster cluster, StringBuilder preCheckErrors) {
// else fail order
if (!NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
if (dataCenter != null && !dataCenter.getInactive()) {
if (!NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
if (vcenter != null && !vcenter.getInactive()) {
VMwareSupport vmware = null;
try {
vmware = new VMwareSupport();
vmware.connect(vcenter.getId());
ClusterComputeResource vcenterCluster = vmware.getCluster(dataCenter.getLabel(), cluster.getLabel(), false);
if (null == vcenterCluster) {
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.notfound.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel()));
} else if (vcenterCluster.getMOR() != null && vcenterCluster.getMOR().getVal() != null && vcenterCluster.getMOR().getVal().equalsIgnoreCase(cluster.getExternalId())) {
ExecutionUtils.currentContext().logInfo("compute.cluster.precheck.cluster.VcenterDataCenter.found.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel());
} else {
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.nomatch.in.vcenter", cluster.getLabel(), vcenter.getLabel()));
}
} catch (ExecutionException e) {
if (e.getCause() instanceof IllegalStateException) {
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.notfound.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel()));
} else {
// exception
throw e;
}
} finally {
if (vmware != null) {
vmware.disconnect();
}
}
} else {
// If the vcenter isn't returned properly, not found in
// DB, but the cluster has a reference to
// it, there's an issue with the sync of the DB object.
// Do not allow the validation to pass
// until that's fixed.
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.improper.vcenter", dataCenter.getVcenter()));
}
} else {
// If datacenter does not have reference to a vcenter then
// there's an issue with the sync of the DB object. Do not allow the validation to pass
// until that's fixed.
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.noVcenter", dataCenter.getLabel()));
}
} else {
// If the datacenter isn't returned properly, not found in DB,
// but the cluster has a reference to
// it, there's an issue with the sync of the DB object. Do not
// allow the validation to pass
// until that's fixed.
preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.improper.VcenterDataCenter", cluster.getVcenterDataCenter()));
}
} else {
// cluster is a vipr cluster only no need to check anything further.
ExecutionUtils.currentContext().logInfo("compute.cluster.precheck.cluster.noVCenterDataCenter", cluster.getLabel());
}
return preCheckErrors;
}
use of com.vmware.vim25.mo.Datacenter in project coprhd-controller by CoprHD.
the class VMwareHostService method validateClusterHosts.
/**
* Validates the vCenter cluster hosts match the same hosts we have in our database for the cluster. If there is a mismatch the check
* will fail the order.
*/
protected void validateClusterHosts() {
if (hostCluster != null) {
VcenterDataCenter datacenter = getModelClient().datacenters().findById(datacenterId);
Cluster cluster = getModelClient().clusters().findById(hostCluster.getId());
ClusterComputeResource vcenterCluster = vmware.getCluster(datacenter.getLabel(), cluster.getLabel(), checkClusterConnectivity());
if (vcenterCluster == null) {
ExecutionUtils.fail("failTask.vmware.cluster.notfound", args(), args(cluster.getLabel()));
}
Set<String> vCenterHostUuids = Sets.newHashSet();
for (HostSystem hostSystem : vcenterCluster.getHosts()) {
if (hostSystem.getHardware() != null && hostSystem.getHardware().systemInfo != null) {
vCenterHostUuids.add(hostSystem.getHardware().systemInfo.uuid);
}
}
List<Host> dbHosts = getModelClient().hosts().findByCluster(hostCluster.getId());
Set<String> dbHostUuids = Sets.newHashSet();
for (Host host : dbHosts) {
// Validate the hosts within the cluster all have good discovery status
if (!DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.toString().equalsIgnoreCase(host.getCompatibilityStatus())) {
ExecutionUtils.fail("failTask.vmware.cluster.hostincompatible", args(), args(cluster.getLabel(), host.getLabel()));
} else if (DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString().equalsIgnoreCase(host.getDiscoveryStatus())) {
ExecutionUtils.fail("failTask.vmware.cluster.hostsdiscoveryfailed", args(), args(cluster.getLabel(), host.getLabel()));
}
dbHostUuids.add(host.getUuid());
}
if (!vCenterHostUuids.equals(dbHostUuids)) {
ExecutionUtils.fail("failTask.vmware.cluster.mismatch", args(), args(cluster.getLabel()));
} else {
info("Hosts in cluster %s matches correctly", cluster.getLabel());
}
}
}
use of com.vmware.vim25.mo.Datacenter in project coprhd-controller by CoprHD.
the class VMwareHostService method getConnectedHost.
/**
* Get the first connected host from the given set of hosts
*
* @param hosts list of hosts
* @param datacenter the datacenter the hosts belong to
* @return connected host or null if no hosts are connected
*/
protected Host getConnectedHost(List<Host> hosts, VcenterDataCenter datacenter) {
for (Host host : hosts) {
HostSystem esxHost = null;
esxHost = vmware.getHostSystem(datacenter.getLabel(), host.getLabel(), false);
if (VMwareSupport.isHostConnected(esxHost)) {
return host;
}
}
return null;
}
use of com.vmware.vim25.mo.Datacenter in project coprhd-controller by CoprHD.
the class VMwareSupport method createNfsDatastore.
/**
* Creates an NFS datastore for a host.
*
* @param host
* the host.
* @param fileSystem
* the file system.
* @param export
* the export.
* @param datacenterId
* the datacenter ID.
* @param datastoreName
* the name of the datastore to create.
* @return datastore
*/
public Datastore createNfsDatastore(HostSystem host, FileShareRestRep fileSystem, FileSystemExportParam export, URI datacenterId, String datastoreName) {
addNfsDatastoreTag(fileSystem, export, datacenterId, datastoreName);
String fileServer = StringUtils.substringBefore(export.getMountPoint(), ":");
String mountPath = StringUtils.substringAfter(export.getMountPoint(), ":");
Datastore datastore = execute(new CreateNfsDatastore(host, fileServer, mountPath, datastoreName));
addAffectedResource(fileSystem);
ExecutionUtils.clearRollback();
return datastore;
}
use of com.vmware.vim25.mo.Datacenter in project coprhd-controller by CoprHD.
the class VMwareSupport method createNfsDatastore.
/**
* Creates an NFS datastore for the hosts in the cluster
*
* @param cluster
* the cluster.
* @param fileSystem
* the file system.
* @param export
* the export.
* @param datacenterId
* the datacenter ID.
* @param datastoreName
* the name of the datastore to create.
* @return datastores
*/
public List<Datastore> createNfsDatastore(ClusterComputeResource cluster, FileShareRestRep fileSystem, FileSystemExportParam export, URI datacenterId, String datastoreName) {
addNfsDatastoreTag(fileSystem, export, datacenterId, datastoreName);
List<Datastore> datastores = Lists.newArrayList();
String fileServer = StringUtils.substringBefore(export.getMountPoint(), ":");
String mountPath = StringUtils.substringAfter(export.getMountPoint(), ":");
for (HostSystem host : cluster.getHosts()) {
datastores.add(execute(new CreateNfsDatastore(host, fileServer, mountPath, datastoreName)));
addAffectedResource(fileSystem);
ExecutionUtils.clearRollback();
}
return datastores;
}
Aggregations