use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class NetworkZoningParam method updateZoningParamUsingFCZoneReference.
/**
* Build the zoningMap attribute of zoningParam using FCZoneReference and exportGroup
*
* @param zoningParam
* @param initsToRemoveOnlyFromZone
* @param exportGroup
*/
public static void updateZoningParamUsingFCZoneReference(List<NetworkZoningParam> zoningParam, List<URI> initsToRemoveOnlyFromZone, ExportGroup exportGroup, DbClient dbClient) {
HashMap<String, Initiator> initiatorMap = new HashMap<String, Initiator>();
for (URI initiatorURI : initsToRemoveOnlyFromZone) {
Initiator iniObject = dbClient.queryObject(Initiator.class, initiatorURI);
String iniString = iniObject.getInitiatorPort().toUpperCase();
initiatorMap.put(iniString, iniObject);
}
// Retrieve FCZoneReference zone references that have the same initiator WWN.
// These zone should be removed. since the initiator is no longer available.
List<FCZoneReference> fcRefs = NetworkUtil.getFCZoneReferencesFromExportGroup(dbClient, exportGroup);
Set<String> iniConsidered = new HashSet<String>();
for (NetworkZoningParam networkZoningParam : zoningParam) {
StringSetMap zoneMap = networkZoningParam.getZoningMap();
if (zoneMap.isEmpty()) {
for (FCZoneReference fcZoneReference : fcRefs) {
String[] initiatorAndPort = getInitiatorAndPortFromPwwnKey(fcZoneReference.getPwwnKey());
if (initiatorAndPort != null) {
String initiator = initiatorAndPort[0];
String port = initiatorAndPort[1];
Initiator iniObject = initiatorMap.get(initiator);
if (iniObject != null) {
StoragePort sp = NetworkUtil.getStoragePort(port, dbClient);
if (sp != null) {
iniConsidered.add(iniObject.getInitiatorPort());
zoneMap.put(iniObject.getId().toString(), sp.getId().toString());
}
}
} else {
_log.warn("Could not obtain initiator and port correctly from the PwwnKey {}", fcZoneReference.getPwwnKey());
}
}
// removed the initiator from map the as this initiator is considered for zone map
if (!iniConsidered.isEmpty()) {
initiatorMap.keySet().removeAll(iniConsidered);
}
}
}
}
use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class NetworkSystemService method deleteNetworkSystem.
/**
* Delete a network system. The method will delete the
* network system and all resources associated with it.
*
* @prereq The network system must be unregistered
* @brief Delete network system
* @return An asynchronous task.
*
* @throws DatabaseException
* When an error occurs querying the database.
*/
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteNetworkSystem(@PathParam("id") URI id) throws DatabaseException {
NetworkSystem system = queryObject(NetworkSystem.class, id, true);
ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
if (!RegistrationStatus.UNREGISTERED.toString().equals(system.getRegistrationStatus())) {
throw APIException.badRequests.invalidParameterCannotDeactivateRegisteredNetworkSystem(system.getId());
}
if (DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString().equals(system.getDiscoveryStatus()) || DiscoveredDataObject.DataCollectionJobStatus.SCHEDULED.toString().equals(system.getDiscoveryStatus())) {
throw APIException.serviceUnavailable.cannotDeactivateStorageSystemWhileInDiscover(system.getId());
}
List<Network> networkList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Network.class, AlternateIdConstraint.Factory.getConstraint(Network.class, "networkSystems", system.getId().toString()));
for (Network network : networkList) {
if (network != null && network.getInactive() != true && network.getConnectedVirtualArrays() != null && !network.getConnectedVirtualArrays().isEmpty() && (network.getNetworkSystems() != null && network.getNetworkSystems().contains(system.getId().toString()) && network.getNetworkSystems().size() == 1)) {
throw APIException.badRequests.invalidParameterNetworkMustBeUnassignedFromVirtualArray(network.getLabel(), system.getLabel());
}
}
Map<String, List<FCZoneReference>> zonesMap = getNetworkSystemZoneRefs(system);
List<URI> nsystems = null;
List<FCZoneReference> zones = null;
// by the purge process
for (Network network : networkList) {
// remove references from ports
nsystems = StringSetUtil.stringSetToUriList(network.getNetworkSystems());
nsystems.remove(system.getId());
if (nsystems.isEmpty()) {
// This network will be removed - Remove any storage port references
List<StoragePort> netPorts = NetworkAssociationHelper.getNetworkStoragePorts(network.getId().toString(), null, _dbClient);
NetworkAssociationHelper.clearPortAssociations(netPorts, _dbClient);
} else {
// This network will remain, update any zone references to use another network system
URI nsUri = nsystems.get(0);
zones = zonesMap.get(network.getNativeId());
if (zones != null) {
for (FCZoneReference zone : zones) {
zone.setNetworkSystemUri(nsUri);
}
_dbClient.updateObject(zones);
}
}
}
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, system.getId(), taskId, ResourceOperationTypeEnum.DELETE_NETWORK_SYSTEM);
PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), system, _retry_attempts, taskId, 60);
auditOp(OperationTypeEnum.DELETE_NETWORK_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, system.getId().toString(), system.getLabel(), system.getPortNumber(), system.getUsername(), system.getSmisProviderIP(), system.getSmisPortNumber(), system.getSmisUserName(), system.getSmisUseSSL(), system.getVersion(), system.getUptime());
return toTask(system, taskId, op);
}
use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class AbstractBlockServiceApiImpl method deleteVolumes.
/**
* {@inheritDoc}
*
* @throws InternalException
*/
@Override
public void deleteVolumes(URI systemURI, List<URI> volumeURIs, String deletionType, String task) throws InternalException {
// Get volume descriptor for all volumes to be deleted.
List<VolumeDescriptor> volumeDescriptors = getDescriptorsForVolumesToBeDeleted(systemURI, volumeURIs, deletionType);
// the controller and delete the volumes.
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deletionType)) {
// Do any cleanup necessary for the ViPR only delete.
cleanupForViPROnlyDelete(volumeDescriptors);
// Mark them inactive. Note that some of the volumes may be mirrors,
// which have a different database type.
List<VolumeDescriptor> descriptorsForMirrors = VolumeDescriptor.getDescriptors(volumeDescriptors, VolumeDescriptor.Type.BLOCK_MIRROR);
_dbClient.markForDeletion(_dbClient.queryObject(BlockMirror.class, VolumeDescriptor.getVolumeURIs(descriptorsForMirrors)));
List<VolumeDescriptor> descriptorsForVolumes = VolumeDescriptor.filterByType(volumeDescriptors, null, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.BLOCK_MIRROR });
_dbClient.markForDeletion(_dbClient.queryObject(Volume.class, VolumeDescriptor.getVolumeURIs(descriptorsForVolumes)));
// Delete the corresponding FCZoneReferences
for (URI volumeURI : volumeURIs) {
List<FCZoneReference> zoneReferences = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, FCZoneReference.class, "volumeUri", volumeURI.toString());
for (FCZoneReference zoneReference : zoneReferences) {
if (zoneReference != null) {
_dbClient.markForDeletion(zoneReference);
}
}
}
// Update the task status for each volume
for (URI volumeURI : volumeURIs) {
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
Operation op = volume.getOpStatus().get(task);
op.ready("Volume succesfully deleted from ViPR");
volume.getOpStatus().updateTaskStatus(task, op);
_dbClient.updateObject(volume);
}
} else {
BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
controller.deleteVolumes(volumeDescriptors, task);
}
}
use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class ExportUtils method getZoneReferences.
/**
* Find the san zone information for the initiator/block object.
*
* @param blockObjectUri the block object URI
* @param initiator the initiator
* @param ports the target ports
* @param refs a map of port-to-zone-reference
* @return the list of san zones created for the initiator if any were created. Otherwise, an returns empty map.
*/
private static Map<StoragePort, FCZoneReference> getZoneReferences(URI blockObjectUri, Initiator initiator, List<StoragePort> ports, Map<StoragePort, List<FCZoneReference>> refs) {
Map<StoragePort, FCZoneReference> targetPortReferences = new HashMap<StoragePort, FCZoneReference>();
if (initiator.getProtocol().equals(Block.FC.name())) {
for (StoragePort port : ports) {
for (FCZoneReference ref : refs.get(port)) {
if (ref != null && !ref.getInactive() && blockObjectUri.equals(ref.getVolumeUri())) {
targetPortReferences.put(port, ref);
// there should be one only
break;
}
}
}
}
_log.debug("Found {} san zone references for initiator {} and block object {}", new Object[] { targetPortReferences.size(), initiator.getInitiatorPort(), blockObjectUri });
return targetPortReferences;
}
use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class ExportUtils method getInitiatorsZoneReferences.
/**
* Find the san zone information for the initiator and storage ports. Returns
* a map of zone references per port.
*
* @param initiator the initiator
* @param ports the target ports
* @param dbClient an instance of {@link DbClient}
* @return a map of san zones created for the initiator grouped by port for
* the list of target ports. Otherwise, an returns empty map.
*/
private static Map<StoragePort, List<FCZoneReference>> getInitiatorsZoneReferences(Initiator initiator, List<StoragePort> ports, DbClient dbClient) {
Map<StoragePort, List<FCZoneReference>> targetPortReferences = new HashMap<StoragePort, List<FCZoneReference>>();
if (initiator.getProtocol().equals(Block.FC.name())) {
List<FCZoneReference> refs = null;
for (StoragePort port : ports) {
String key = FCZoneReference.makeEndpointsKey(Arrays.asList(initiator.getInitiatorPort(), port.getPortNetworkId()));
refs = new ArrayList<FCZoneReference>();
targetPortReferences.put(port, refs);
URIQueryResultList queryList = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFCZoneReferenceKeyConstraint(key), queryList);
Iterator<FCZoneReference> refsUris = dbClient.queryIterativeObjects(FCZoneReference.class, iteratorToList(queryList));
FCZoneReference ref = null;
while (refsUris.hasNext()) {
ref = refsUris.next();
if (ref != null && !ref.getInactive()) {
refs.add(ref);
}
}
}
}
return targetPortReferences;
}
Aggregations