use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class ControllerLockingUtil method getHostStorageLockKeys.
/**
* Returns a list of lock keys for export of Hosts to StorageSystems.
* This is constructed from a list of Initiators.
* All the host URIs are collected from the Initiators.
* If an Initiator does not have a host URI, its hostName is converted to a URI and used.
* iF export type is Cluster, the clusters are looked up, and all hosts in the
* cluster are used.
* The keys are constructed from a concatenation of the host URI and the storage system URI.
*
* @param dbClient
* @param type
* ExportGroup.ExportGroupType -- used to determine if cluster export
* @param initiatorURIs
* -- set of Initiators to consider
* @param storageURI
* -- URI of storage system
* (could be a Protection System or null in which case only host in key)
* @return List<String> where each item in list is a lockKey
*/
public static List<String> getHostStorageLockKeys(DbClient dbClient, ExportGroup.ExportGroupType type, Collection<URI> initiatorURIs, URI storageURI) {
String storageKey = getStorageKey(dbClient, storageURI);
List<String> lockKeys = new ArrayList<String>();
// Collect the needed hosts, which can be specified either by URI or string name.
Set<URI> hostURIs = new HashSet<URI>();
Set<String> hostNames = new HashSet<String>();
for (URI initiatorURI : initiatorURIs) {
Initiator initiator = dbClient.queryObject(Initiator.class, initiatorURI);
if (initiator == null || initiator.getInactive()) {
continue;
}
hostURIs.add(initiator.getHost());
hostNames.add(initiator.getHostName());
}
// If the export is type cluster, we want to add ALL the hosts in the clusters.
if (type.equals(ExportGroup.ExportGroupType.Cluster)) {
Set<URI> clusterURIs = new HashSet<URI>();
// First determine the clusters for each real host.
for (URI hostURI : hostURIs) {
Host host = dbClient.queryObject(Host.class, hostURI);
if (host == null || host.getInactive()) {
continue;
}
if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
clusterURIs.add(host.getCluster());
}
}
// add those hosts if not already present.
for (URI clusterURI : clusterURIs) {
URIQueryResultList result = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getContainedObjectsConstraint(clusterURI, Host.class, "cluster"), result);
Iterator<URI> iter = result.iterator();
while (iter.hasNext()) {
Host host = dbClient.queryObject(Host.class, iter.next());
if (host == null || host.getInactive()) {
continue;
}
hostNames.add(host.getHostName());
}
}
}
// Now make a key for every host / storage pair
for (String hostName : hostNames) {
String key = hostName + DELIMITER + storageKey;
key = key.replaceAll("\\s", "");
if (!lockKeys.contains(key)) {
lockKeys.add(key);
}
}
log.info("Lock keys: " + lockKeys.toString());
return lockKeys;
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class VcenterDiscoveryAdapter method deleteDatacenters.
private void deleteDatacenters(Iterable<VcenterDataCenter> datacenters, List<URI> deletedHosts, List<URI> deletedClusters) {
for (VcenterDataCenter datacenter : datacenters) {
boolean containsHosts = false;
boolean clustersInUse = false;
for (Cluster cluster : getClusters(datacenter)) {
deletedClusters.add(cluster.getId());
}
for (Host host : getHosts(datacenter)) {
deletedHosts.add(host.getId());
containsHosts = true;
}
for (Cluster cluster : getClusters(datacenter)) {
URI clusterId = cluster.getId();
List<URI> hostUris = ComputeSystemHelper.getChildrenUris(dbClient, clusterId, Host.class, "cluster");
if (hostUris.isEmpty() && !ComputeSystemHelper.isClusterInExport(dbClient, clusterId) && EventUtils.findAffectedResourcePendingEvents(dbClient, clusterId).isEmpty()) {
info("Deactivating Cluster: " + clusterId);
ComputeSystemHelper.doDeactivateCluster(dbClient, cluster);
} else {
info("Unable to delete cluster " + clusterId);
clustersInUse = true;
}
}
// delete datacenters that don't contain any clusters or hosts, don't have any exports, and don't have any pending events
if (!containsHosts && !clustersInUse && !ComputeSystemHelper.isDataCenterInUse(dbClient, datacenter.getId()) && EventUtils.findAffectedResourcePendingEvents(dbClient, datacenter.getId()).isEmpty()) {
info("Deactivating Datacenter: " + datacenter.getId());
ComputeSystemHelper.doDeactivateVcenterDataCenter(dbClient, datacenter);
} else {
info("Unable to delete datacenter " + datacenter.getId());
}
}
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class VcenterDiscoveryAdapter method discoveryFailure.
@Override
public void discoveryFailure(DiscoveredSystemObject target, String compatibilityStatus, String errorMessage) {
super.discoveryFailure(target, compatibilityStatus, errorMessage);
Vcenter vcenter = getModelClient().vcenters().findById(target.getId());
Iterable<VcenterDataCenter> dataCenters = getModelClient().datacenters().findByVCenter(vcenter.getId(), true);
for (VcenterDataCenter dataCenter : dataCenters) {
Iterable<Host> hosts = getModelClient().hosts().findByVcenterDatacenter(dataCenter.getId());
for (Host host : hosts) {
host.setDiscoveryStatus(DataCollectionJobStatus.ERROR.name());
host.setLastDiscoveryRunTime(System.currentTimeMillis());
host.setCompatibilityStatus(compatibilityStatus);
host.setLastDiscoveryStatusMessage("vCenter Discovery Failed: " + errorMessage);
save(host);
}
}
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class DataSourceFactory method createHSDNickNameDataSource.
/**
* Creates a datasource for resolving HSD's nickname
*
* @param hostName - host name
* @param storagePortNumber - HDS storage port number
* @return a data source populated with the properties needed
*/
public DataSource createHSDNickNameDataSource(String hostName, String storagePortNumber, StorageSystem storageSystem) {
Host host = getHostByName(hostName);
Map<String, String> computedValueMap = new HashMap<String, String>();
computedValueMap.put(CustomConfigConstants.HDS_STORAGE_PORT_NUMBER, storagePortNumber);
return createDataSource(CustomConfigConstants.HDS_HOST_STORAGE_DOMAIN_NICKNAME_MASK_NAME, new DataObject[] { host, storageSystem }, computedValueMap);
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class DataSourceFactory method createExportMaskDataSource.
/**
* Creates a datasource used for export operations
*
* @param configName - name of the config for which the export datasource should be created
* @param hostName - host name
* @param clusterName - cluster name
* @param storageSystem - storage system instance
* @return a data source populated with the properties needed
*/
public DataSource createExportMaskDataSource(String configName, String hostName, String clusterName, StorageSystem storageSystem) {
// for host, get the object because the name may query for host type
Host host = getHostByName(hostName);
// for cluster, just create an in-memory object, cluster has no other attributes
Cluster cluster = new Cluster();
if (!Strings.isNullOrEmpty(clusterName)) {
cluster.setLabel(clusterName);
}
return createExportMaskDataSource(configName, host, cluster, storageSystem);
}
Aggregations