use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.
the class BlockStorageUtils method addClusterToExport.
public static void addClusterToExport(URI exportId, URI cluster, Integer minPaths, Integer maxPaths, Integer pathsPerInitiator, URI portGroup) {
Task<ExportGroupRestRep> task = execute(new AddClusterToExport(exportId, cluster, minPaths, maxPaths, pathsPerInitiator, portGroup));
addRollback(new DeactivateBlockExport(exportId));
addAffectedResource(task);
}
use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.
the class ResourceUtils method getHostExports.
public static List<HostExport> getHostExports(Collection<ITLRestRep> itls) {
Map<URI, HostExport> hostExports = Maps.newLinkedHashMap();
Map<ITLRestRep, ExportGroupRestRep> exportMap = getExportMap(itls);
for (Map.Entry<ITLRestRep, ExportGroupRestRep> entry : exportMap.entrySet()) {
HostRestRep host = getHost(entry.getKey(), entry.getValue());
if (host == null) {
continue;
}
HostExport hostExport = hostExports.get(host.getId());
if (hostExport == null) {
hostExport = createHostExport(host);
hostExports.put(host.getId(), hostExport);
}
hostExport.exportMap.put(entry.getKey(), entry.getValue());
}
return Lists.newArrayList(hostExports.values());
}
use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.
the class ViPRClientApp method createBlockVolumeForHost.
public void createBlockVolumeForHost() {
List<HostRestRep> hosts = client.hosts().getByUserTenant(HostTypeFilter.ESX.not());
// User choice
HostRestRep selectedHost = chooseHost(hosts);
List<VirtualArrayRestRep> virtualArrays = client.varrays().findByConnectedHost(selectedHost);
// User choice
VirtualArrayRestRep selectedVirtualArray = chooseVirtualArray(virtualArrays);
List<BlockVirtualPoolRestRep> virtualPools = client.blockVpools().getByVirtualArray(selectedVirtualArray.getId());
// User choice
BlockVirtualPoolRestRep selectedVirtualPool = chooseVirtualPool(virtualPools);
List<ProjectRestRep> projects = client.projects().getByUserTenant();
// User choice
ProjectRestRep selectedProject = chooseProject(projects);
URI volumeId = createVolume(selectedVirtualArray, selectedVirtualPool, selectedProject);
List<ExportGroupRestRep> exports = new ArrayList<>();
if (exports.isEmpty()) {
createExport(volumeId, selectedHost, selectedVirtualArray, selectedProject);
} else {
addVolumeToExport(volumeId, exports.get(0));
}
}
use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.
the class ComputeUtils method deactivateHostsNotAddedToCluster.
/**
* validate that specified hosts are in the cluster export groups, else deactivate the host
* @param List to hosts to check
* @param Cluster
* @return list of goodHosts ie hosts that are in the cluster EGs.
*/
public static List<Host> deactivateHostsNotAddedToCluster(List<Host> hosts, Cluster cluster) {
List<Host> hostsToRemove = new ArrayList<Host>();
List<Host> goodHosts = new ArrayList<Host>();
if ((hosts != null) && (cluster != null)) {
List<ExportGroupRestRep> exports = BlockStorageUtils.findExportsContainingCluster(cluster.getId(), null, null);
if (exports != null) {
for (Host host : hosts) {
boolean hostAddedToExports = true;
for (ExportGroupRestRep exportGroup : exports) {
List<HostRestRep> exportedHosts = exportGroup.getHosts();
boolean found = false;
for (HostRestRep exportedHost : exportGroup.getHosts()) {
if (host.getId().equals(exportedHost.getId())) {
found = true;
break;
}
}
if (!found) {
hostAddedToExports = false;
ExecutionUtils.currentContext().logError("computeutils.clusterexport.hostnotadded", host.getLabel(), exportGroup.getGeneratedName());
} else {
ExecutionUtils.currentContext().logInfo("computeutils.clusterexport.hostadded", host.getLabel(), exportGroup.getGeneratedName());
}
}
if (hostAddedToExports) {
goodHosts.add(host);
} else {
hostsToRemove.add(host);
}
}
}
}
if (!hostsToRemove.isEmpty()) {
for (Host host : hostsToRemove) {
try {
execute(new RemoveHostFromCluster(host.getId()));
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.deactivatehost.failure", host.getHostName(), e.getMessage());
}
}
try {
List<Host> hostsRemoved = deactivateHosts(hostsToRemove);
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.deactivatehost.deactivate.failure", e.getMessage());
}
}
return goodHosts;
}
use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.
the class ComputeUtils method exportBootVols.
/**
* Exports all boot volumes to respective hosts.
*
* Since exporting to boot volumes requires only one volume be exported for OS install, we have extra checks
* in here:
* - If there is an existing EG with the same name, we need to make additional checks:
* - If the EG has no initiators and volumes, re-use it. Add the host and volume.
* - If the EG has our initiators and a volume (or more), error out.
* - If the EG has different initiators, create an EG with a different name.
* - If the EG has our initiators and no volumes, re-use it. Add the volume only.
*
* @param hostToVolumeIdMap host to boot volume ID map
* @param project project
* @param virtualArray virtual array
* @param hlu HLU
* @param portGroup port group URI
* @return returns a map of hosts to Export Group URIs
*/
public static Map<Host, URI> exportBootVols(Map<Host, URI> hostToVolumeIdMap, URI project, URI virtualArray, Integer hlu, URI portGroup) {
if (hostToVolumeIdMap == null || hostToVolumeIdMap.isEmpty()) {
return Maps.newHashMap();
}
Map<Task<ExportGroupRestRep>, Host> taskToHostMap = new HashMap<>();
for (Entry<Host, URI> hostToVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
Host host = hostToVolumeIdEntry.getKey();
URI volumeId = hostToVolumeIdEntry.getValue();
if (!NullColumnValueGetter.isNullURI(volumeId) && (host != null) && !(host.getInactive())) {
try {
ExportGroupRestRep export = BlockStorageUtils.findExportByHost(host, project, virtualArray, null);
if (export != null && !export.getVolumes().isEmpty()) {
throw new IllegalStateException(new Throwable("Existing export contains other volumes. Controller supports only the boot volume visible to host." + host.getHostName()));
}
// We can add the host to that export group if it's empty.
if (export == null) {
export = BlockStorageUtils.findExportsByName(host.getHostName(), project, virtualArray);
}
boolean createExport = export == null;
boolean isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
String exportName = host.getHostName();
if (export != null && !isEmptyExport) {
exportName = exportName + BlockStorageUtils.UNDERSCORE + new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
createExport = true;
}
Task<ExportGroupRestRep> task = null;
if (createExport) {
task = BlockStorageUtils.createHostExportNoWait(exportName, project, virtualArray, Arrays.asList(volumeId), hlu, host, portGroup);
} else {
task = BlockStorageUtils.addHostAndVolumeToExportNoWait(export.getId(), // Don't add the host if there are already initiators in this export group.
export.getInitiators() != null && !export.getInitiators().isEmpty() ? null : host.getId(), volumeId, hlu, portGroup);
}
taskToHostMap.put(task, host);
} catch (ExecutionException e) {
String errorMessage = e.getMessage() == null ? "" : e.getMessage();
ExecutionUtils.currentContext().logError("computeutils.exportbootvolumes.failure", host.getHostName(), errorMessage);
}
// prevent exports from rolling back on exception
ExecutionUtils.clearRollback();
}
}
// Monitor tasks
Map<Host, URI> hostToEgIdMap = new HashMap<>();
List<Task<ExportGroupRestRep>> tasks = new ArrayList<>(taskToHostMap.keySet());
while (!tasks.isEmpty()) {
tasks = waitAndRefresh(tasks);
for (Task<ExportGroupRestRep> successfulTask : getSuccessfulTasks(tasks)) {
URI exportId = successfulTask.getResourceId();
addAffectedResource(exportId);
hostToEgIdMap.put(taskToHostMap.get(successfulTask), exportId);
tasks.remove(successfulTask);
}
for (Task<ExportGroupRestRep> failedTask : getFailedTasks(tasks)) {
String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
ExecutionUtils.currentContext().logError("computeutils.exportbootvolumes.failure", failedTask.getResource().getName(), errorMessage);
tasks.remove(failedTask);
}
}
return hostToEgIdMap;
}
Aggregations