use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class StoragePortService method updateStoragePortNetwork.
/**
* Updates the network for the passed storage port. If the passed new
* network id is not null, then the storage port will be unassigned from its
* current network, if any, and reassigned to the new network. Note however,
* that a storage port that is currently a member of a discovered network
* cannot be reassigned to a new network. Attempting to do so results in a
* bad request exception. Attempts to reassign to the same network are
* logged and ignored. If the passed new network id is not null, but
* is instead "" or "null", and the storage port is currently assigned
* to an undiscovered network, the port will be unassigned from the network.
*
* @param storagePort A reference to the storage port.
* @param newNetworkId The requested new network id.
*
* @return true if the there was a network change made, false otherwise.
*/
private boolean updateStoragePortNetwork(StoragePort storagePort, URI newNetworkId) {
boolean networkUpdated = false;
String portNetworkId = storagePort.getPortNetworkId();
String portNativeId = storagePort.getNativeGuid();
Network currentNetwork = null;
Network newNetwork = null;
// of "" or "null".
if (newNetworkId == null) {
_log.info("New network id was not specified.");
return false;
}
// If we're removing the port from an old Network, check it was not
// discovered in it.
URI currentNetworkId = storagePort.getNetwork();
if (!NullColumnValueGetter.isNullURI(currentNetworkId)) {
_log.info("Current storage port network is {}", currentNetworkId);
currentNetwork = _dbClient.queryObject(Network.class, currentNetworkId);
ArgValidator.checkEntity(currentNetwork, currentNetworkId, false);
if (currentNetwork.endpointIsDiscovered(storagePort.getPortNetworkId())) {
throw APIException.badRequests.unableToUpdateDiscoveredNetworkForStoragePort();
}
}
// If we're assigning a new Network, check it is a valid Network.
if (!NullColumnValueGetter.isNullURI(newNetworkId)) {
_log.info("New network {} specified for storage port ", newNetworkId, portNativeId);
// Validate the new network exists and is active.
ArgValidator.checkFieldUriType(newNetworkId, Network.class, "network");
newNetwork = _dbClient.queryObject(Network.class, newNetworkId);
ArgValidator.checkEntity(newNetwork, newNetworkId, isIdEmbeddedInURL(newNetworkId));
// the endpoint. This is just a warning.
if (newNetwork.getDiscovered()) {
if (false == newNetwork.retrieveEndpoints().contains(portNetworkId)) {
_log.info(String.format("Network does not contain " + "endpoint for port %s wwpn %s", storagePort.getPortName(), portNetworkId));
}
}
}
if ((currentNetwork == null && newNetwork == null) || (currentNetwork != null && newNetwork != null && currentNetworkId.equals(newNetworkId))) {
_log.info("The old and new Networks are the same, no change will be made.");
return false;
}
if (newNetwork != null) {
// If adding or changing network assignment.
_log.info("Storage port {} will be assigned to network {}", portNativeId, newNetwork.getLabel());
updateNetworkEndpoint(newNetworkId, portNetworkId, NetworkEndpointParam.EndpointOp.add);
networkUpdated = true;
} else if (currentNetwork != null) {
// If removing from the current network assignment.
_log.info("Storage port {} will be removed from network {}", portNativeId, currentNetwork.getLabel());
updateNetworkEndpoint(currentNetworkId, portNetworkId, NetworkEndpointParam.EndpointOp.remove);
networkUpdated = true;
}
return networkUpdated;
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class StoragePortService method updateStoragePortVirtualArrays.
/**
* Updates the virtual arrays to which the port is assigned.
*
* @param storagePort A reference to the storage port.
* @param varrayChanges The virtual array changes.
*
* @return true if there was a virtual array assignment change, false otherwise.
*/
private boolean updateStoragePortVirtualArrays(StoragePort storagePort, VirtualArrayAssignmentChanges varrayAssignmentChanges) {
// Validate that the virtual arrays to be assigned to the storage port
// reference existing virtual arrays in the database and add them to
// the storage port.
boolean varraysForPortUpdated = false;
Set<String> varraysAddedToPort = new HashSet<String>();
Set<String> varraysRemovedFromPort = new HashSet<String>();
if (varrayAssignmentChanges != null) {
_log.info("Update request has virtual array assignment changes for storage port {}", storagePort.getId());
// Verify the assignment changes in the request.
verifyAssignmentChanges(storagePort, varrayAssignmentChanges);
_log.info("Requested virtual array assignment changes verified.");
VirtualArrayAssignments addAssignments = varrayAssignmentChanges.getAdd();
if (addAssignments != null) {
Set<String> addVArrays = addAssignments.getVarrays();
if ((addVArrays != null) && (!addVArrays.isEmpty())) {
_log.info("Request specifies virtual arrays to be added.");
// Validate the requested URIs.
VirtualArrayService.checkVirtualArrayURIs(addVArrays, _dbClient);
// Iterate over the virtual arrays and assign them
// to the storage port.
StringSet currentAssignments = storagePort.getAssignedVirtualArrays();
Iterator<String> addVArraysIter = addVArrays.iterator();
while (addVArraysIter.hasNext()) {
String addVArrayId = addVArraysIter.next();
if ((currentAssignments != null) && (currentAssignments.contains(addVArrayId))) {
// Just ignore those already assigned
_log.info("Storage port already assigned to virtual array {}", addVArrayId);
continue;
}
varraysAddedToPort.add(addVArrayId);
varraysForPortUpdated = true;
_log.info("Storage port will be assigned to virtual array {}", addVArrayId);
}
}
}
// Validate that the virtual arrays to be unassigned from the
// storage port reference existing virtual arrays in the database
// and remove them from the storage port.
VirtualArrayAssignments removeAssignments = varrayAssignmentChanges.getRemove();
if (removeAssignments != null) {
Set<String> removeVArrays = removeAssignments.getVarrays();
if ((removeVArrays != null) && (!removeVArrays.isEmpty())) {
_log.info("Request specifies virtual arrays to be removed.");
// Validate the requested URIs.
VirtualArrayService.checkVirtualArrayURIs(removeVArrays, _dbClient);
// Iterate over the virtual arrays and unassign from
// the storage port.
StringSet currentAssignments = storagePort.getAssignedVirtualArrays();
Iterator<String> removeVArraysIter = removeVArrays.iterator();
while (removeVArraysIter.hasNext()) {
String removeVArrayId = removeVArraysIter.next();
if ((currentAssignments == null) || (!currentAssignments.contains(removeVArrayId))) {
// Just ignore those not assigned.
_log.info("Storage port is not assigned to virtual array {}", removeVArrayId);
continue;
}
// storagePort.removeAssignedVirtualArray(removeVArrayId);
varraysRemovedFromPort.add(removeVArrayId);
varraysForPortUpdated = true;
_log.info("Storage port will be unassigned from virtual array {}", removeVArrayId);
}
}
}
}
// Persist virtual array changes for storage port, if any.
if (varraysForPortUpdated) {
storagePort.addAssignedVirtualArrays(varraysAddedToPort);
storagePort.removeAssignedVirtualArrays(varraysRemovedFromPort);
// Check the new virtual array assignment does
// not remove the port from varrays where it is used
verifyPortNoInUseInRemovedVarrays(storagePort);
_dbClient.updateAndReindexObject(storagePort);
// Because the storage port virtual array assignments have
// changed, we may have to update the implicit connected
// virtual arrays for the storage port's network.
URI storagePortNetworkURI = storagePort.getNetwork();
if (storagePortNetworkURI != null) {
// TODO - I need to find a way around using a full network retrieval
Network storagePortNetwork = _dbClient.queryObject(Network.class, storagePortNetworkURI);
if (storagePortNetwork != null) {
if (!varraysRemovedFromPort.isEmpty()) {
// if varrays were removed, it will be a full reset
// this will take care of both add and remove, but costly
NetworkAssociationHelper.updateConnectedVirtualArrays(storagePortNetwork, Collections.singletonList(storagePort), false, _dbClient);
} else if (!varraysAddedToPort.isEmpty()) {
// if varrays were only added, do add only, cheaper
NetworkAssociationHelper.updateConnectedVirtualArrays(storagePortNetwork, Collections.singletonList(storagePort), true, _dbClient);
}
}
}
}
return varraysForPortUpdated;
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class StoragePortService method updateNetworkEndpoint.
/**
* Utility method to add/remove storage port endpoints to/from transport
* zones. The {@link NetworkService#doUpdateEndpoints(URI, NetworkEndpointParam)} handles updating the transport zone as well as the
* port and pool
* associations. When a port is added:
* <ul>
* <li>the port's endpoint is added to the Network</li>
* <li>The port Network is set to the new Network</li>
* <li>The pool-to-varray associations are updated if needed.</li>
* <li>If the ports exists in another Network, its endpoint is removed from the old Network and the pool-to-varray associations are also
* updated</li>
* </ul>
* When a port is removed:
* <ul>
* <li>the port's endpoint is removed from the Network</li>
* <li>The port Network is set null</li>
* <li>The pool-to-varray associations are updated if needed.</li>
* </ul>
*
* @param transportZoneURI The URI of the Network.
* @param endpointNetworkId The network id of the storage port.
* @param op The operation, add/remove
*/
private void updateNetworkEndpoint(URI transportZoneURI, String endpointNetworkId, NetworkEndpointParam.EndpointOp op) {
// Set up the parameters to add/remove the storage port endpoint
NetworkEndpointParam param = new NetworkEndpointParam();
List<String> endpoints = new ArrayList<String>();
endpoints.add(endpointNetworkId);
param.setEndpoints(endpoints);
param.setOp(op.name());
// Add/Remove the storage port endpoint to/from the Network.
Network network = networkSvc.doUpdateEndpoints(transportZoneURI, param);
_dbClient.updateAndReindexObject(network);
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class StoragePortService method updateStoragePort.
/**
* Updates Network for the storage port with the passed
* id and/or updates the virtual arrays to which the storage
* port is assigned.
* <p>
* A port's network is used to determine to which initiators the port can be exported. It also determines the port's virtual arrays when
* the port is not explicitly assigned to virtual arrays ( see {@link StoragePort#getAssignedVirtualArrays()}). In this case the port's
* virtual arrays are the same as its networks virtual arrays (see {@link StoragePort#getConnectedVirtualArrays()}). Implicit virtual
* arrays cannot be removed, they can only be overridden by an explicit assignment or automatically unassigned when the network is
* unassigned from a virtual array. A port's effective virtual array assignment is {@link StoragePort#getTaggedVirtualArrays()}).
* <p>
* A port can be explicitly assigned to virtual arrays and this overrides the implicit assignment resulting from the network
* association. If the explicit assignment is removed, the implicit assignment becomes effective again.
* <p>
* Managing ports virtual array assignments requires planning. In general, networks need not to be assigned to virtual arrays unless
* implicit assignments of ports are desired.
*
* @param id the URN of a ViPR storage port.
* @param storagePortUpdates Specifies the updates to be made to the storage
* port
*
* @brief Update storage port network and/or virtual array assignments.
* @return A StoragePortRestRep specifying the updated storage port info.
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StoragePortRestRep updateStoragePort(@PathParam("id") URI id, StoragePortUpdate storagePortUpdates) {
// Get the storage port with the passed id.
ArgValidator.checkFieldUriType(id, StoragePort.class, "id");
StoragePort storagePort = queryResource(id);
_log.info("Update called for storage port {}", id);
// If the port is a VPLEX, then before any changes are
// made for the port, get the storage pools for the systems
// connected to the VPLEX. These pools and the vpools they
// match may be impacted by the change to the VPLEX storage
// port. We must get these ports now before any changes are
// persisted for the port as the connected systems may
// change and we would not get all potentially impacted pools.
List<StoragePool> modifiedPools = null;
URI systemURI = storagePort.getStorageDevice();
StorageSystem system = _dbClient.queryObject(StorageSystem.class, systemURI);
if (DiscoveredDataObject.Type.vplex.name().equals(system.getSystemType())) {
modifiedPools = StoragePoolAssociationHelper.getStoragePoolsFromPorts(_dbClient, Arrays.asList(storagePort), null, true);
}
// Get the old network as part of storage port.
URI oldNetworkId = storagePort.getNetwork();
// Update the storage port network assignment.
URI newNetworkId = storagePortUpdates.getNetwork();
_log.info("Checking for updates to storage port network.");
boolean networkUpdated = updateStoragePortNetwork(storagePort, newNetworkId);
if (networkUpdated) {
_log.info("Storage port network has been modified.");
// No need to update pool connectivity because the call to network service handles that
// Get the updated reference.
storagePort = queryResource(id);
}
// Update the storage port virtual array assignments.
_log.info("Checking for updates to storage port virtual array assignments.");
boolean virtualArraysUpdated = updateStoragePortVirtualArrays(storagePort, storagePortUpdates.getVarrayChanges());
/**
* This is applicable only for Cinder Storage System's port
* as currently there is no API to discover it from Cinder.
* So, it requires user to update the value for provisioning operations.
*/
boolean portNetworkIdUpdated = updatePortNetworkId(storagePort, storagePortUpdates.getPortNetworkId());
// associations when a storage port is modified.
if (DiscoveredDataObject.Type.vplex.name().equals(system.getSystemType())) {
List<StoragePool> pools = StoragePoolAssociationHelper.getStoragePoolsFromPorts(_dbClient, Arrays.asList(storagePort), null, true);
if ((modifiedPools == null) || (modifiedPools.isEmpty())) {
modifiedPools = pools;
} else {
List<StoragePool> poolsToAdd = new ArrayList<StoragePool>();
for (StoragePool pool : pools) {
URI poolURI = pool.getId();
boolean poolFound = false;
for (StoragePool modifiedPool : modifiedPools) {
if (poolURI.equals(modifiedPool.getId())) {
poolFound = true;
break;
}
}
if (!poolFound) {
poolsToAdd.add(pool);
}
}
modifiedPools.addAll(poolsToAdd);
}
}
if (networkUpdated || portNetworkIdUpdated) {
_log.info("Storage port was moved to other network.");
// this method runs standard procedure for poolmatcher, rp connectivity
StoragePortAssociationHelper.runUpdatePortAssociationsProcess(Collections.singleton(storagePort), null, _dbClient, _coordinator, modifiedPools);
} else if (virtualArraysUpdated) {
_log.info("Storage port virtual arrays have been modified.");
// this method runs optimized procedure for poolmatcher, rp connectivity
StoragePortAssociationHelper.runUpdatePortAssociationsProcessForVArrayChange(storagePort, _dbClient, _coordinator, modifiedPools, storagePortUpdates.getVarrayChanges());
}
// Update the virtual nas virtual arrays with network virtual arrays!!!
if (DiscoveredDataObject.Type.vnxfile.name().equals(system.getSystemType()) || DiscoveredDataObject.Type.isilon.name().equals(system.getSystemType())) {
Network newNetwork = null;
boolean removePort = false;
if (networkUpdated) {
if (!NullColumnValueGetter.isNullURI(newNetworkId)) {
_log.info("New network {} specified for vNAS storage port ", newNetworkId);
// Validate the new network exists and is active.
newNetwork = _dbClient.queryObject(Network.class, newNetworkId);
} else if (!NullColumnValueGetter.isNullURI(oldNetworkId)) {
_log.info("Removing network {} from vNAS storage port ", oldNetworkId);
// Validate the new network exists and is active.
newNetwork = _dbClient.queryObject(Network.class, oldNetworkId);
removePort = true;
}
// Update the virtual nas virtual array assignments.
_log.info("Checking for updates to virtual nas virtual array assignments.");
boolean vNasVirtualArraysUpdated = updatevNasVirtualArrays(storagePort, newNetwork, storagePortUpdates.getVarrayChanges(), removePort);
}
}
// event.
if (networkUpdated || virtualArraysUpdated || portNetworkIdUpdated) {
// Create the audit log entry.
auditOp(OperationTypeEnum.UPDATE_STORAGE_PORT, true, null, storagePort.getLabel(), id.toString());
// Record the storage port update event.
recordStoragePortEvent(OperationTypeEnum.STORAGE_PORT_UPDATE, STORAGEPORT_UPDATED_DESCRIPTION, storagePort.getId());
}
return MapStoragePort.getInstance(_dbClient).toStoragePortRestRep(storagePort);
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkService method getAllNetworks.
/**
* This call returns a list of all the networks, regardless of whether or not
* they are associated with a virtual array.
* <p>
* If network systems are discovered, fiber channel networks that are discovered are not initially associated with virtual array. The
* discovered networks must be updated to associate then with virtual arrays.
*
* @brief List networks
* @return a list of all networks
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public NetworkList getAllNetworks(@QueryParam("wwn") String wwn) {
NetworkList tzlist = new NetworkList();
if (wwn != null) {
// Validate the argument for wwn structure...
ArgValidator.checkFieldValidWwn(wwn);
// Normalize wwn for colon-separated and all-caps
wwn = WwnUtils.convertWWN(wwn.toUpperCase(), FORMAT.COLON);
Network network = NetworkUtil.getEndpointNetwork(wwn, _dbClient);
if (network != null) {
tzlist.getNetworks().add(toNamedRelatedResource(ResourceTypeEnum.NETWORK, network.getId(), network.getLabel()));
}
} else {
List<URI> networks = _dbClient.queryByType(Network.class, true);
List<Network> transportZones = _dbClient.queryObject(Network.class, networks);
for (Network network : transportZones) {
if (network == null || network.getInactive() == true) {
continue;
}
tzlist.getNetworks().add(toNamedRelatedResource(ResourceTypeEnum.NETWORK, network.getId(), network.getLabel()));
}
}
return tzlist;
}
Aggregations