Search in sources :

Example 31 with StoragePort

use of com.emc.storageos.db.client.model.StoragePort in project coprhd-controller by CoprHD.

the class StoragePortService method updatevNasVirtualArrays.

/**
 * Updates the virtual arrays to which the port of virtual nas is assigned.
 *
 * @param storagePort A reference to the storage port.
 * @param newNetwork Network service assicated with varray
 * @param varrayAssignmentChanges The virtual array changes.
 * @param removePort - is port remove or add
 * @return true if there was a virtual array assignment change, false otherwise.
 */
private boolean updatevNasVirtualArrays(StoragePort storagePort, Network newNetwork, VirtualArrayAssignmentChanges varrayAssignmentChanges, boolean removePort) {
    _log.info("StoragePort:updatevNasVirtualArrays {} ", storagePort.getLabel());
    // Validate that the virtual arrays to be assigned to the vnas
    // reference existing virtual arrays in the database and add them to
    // the vnas.
    Set<String> varraysAddedTovNas = new HashSet<String>();
    Set<String> varraysRemovedFromvNas = new HashSet<String>();
    boolean varraysForvNasUpdated = false;
    VirtualNAS vNas = getVirtualNasForStoragePort(storagePort);
    if (vNas == null) {
        _log.info("No Virtual NAS found for port {} ", storagePort.getLabel());
        return false;
    }
    VirtualArrayAssignments addAssignments = null;
    VirtualArrayAssignments removeAssignments = null;
    StringSet currentAssignmentsForvNas = null;
    if (varrayAssignmentChanges != null) {
        addAssignments = varrayAssignmentChanges.getAdd();
        removeAssignments = varrayAssignmentChanges.getRemove();
        currentAssignmentsForvNas = vNas.getAssignedVirtualArrays();
    }
    // Update the vNas virtual arrays from network!!!
    if (newNetwork != null) {
        StringSet vArrays = newNetwork.getAssignedVirtualArrays();
        if (vArrays != null && !vArrays.isEmpty()) {
            if (!removePort) {
                vNas.addAssignedVirtualArrays(vArrays);
                varraysForvNasUpdated = true;
            } else {
                // Removing storage port from netwok!!!
                _log.info("Step to Removing storage port from netwok");
                StringSet vNasVarrys = new StringSet();
                StringSet vNasVarryOther = new StringSet();
                for (String sp : vNas.getStoragePorts()) {
                    StoragePort vNasSp = _dbClient.queryObject(StoragePort.class, URI.create(sp));
                    if (!sp.equalsIgnoreCase(storagePort.getId().toString())) {
                        if (vNasSp.getConnectedVirtualArrays() != null && !vNasSp.getConnectedVirtualArrays().isEmpty()) {
                            vNasVarrys.addAll(vNasSp.getConnectedVirtualArrays());
                        }
                    }
                }
                if (!vNasVarrys.isEmpty()) {
                    _log.info("varrays of vNas other ports {} and varrays of a network {}", vNasVarrys.toString(), vArrays.toString());
                }
                /*
                        If the varray of the port to be deleted is common with another port then we should not update vnas.
                        because the other ports of vnas may exist with same network of deleting port
                    */
                if ((vNasVarrys.isEmpty()) || (!vNasVarrys.isEmpty() && !vNasVarrys.containsAll(vArrays))) {
                    _log.info("Remove the varray from vNAS {} ", vNasVarrys.toString());
                    vNas.getAssignedVirtualArrays().removeAll(vArrays);
                    // remaining vNASvarray of other ports
                    vNas.getAssignedVirtualArrays().addAll(vNasVarrys);
                    varraysForvNasUpdated = true;
                }
            }
        }
    }
    if (varrayAssignmentChanges != null) {
        if (addAssignments != null) {
            Set<String> addVArrays = addAssignments.getVarrays();
            if ((addVArrays != null) && (!addVArrays.isEmpty())) {
                // Iterate over the virtual arrays and assign them
                // to the virtual NAS.
                Iterator<String> addVArraysIterForvNas = addVArrays.iterator();
                while (addVArraysIterForvNas.hasNext()) {
                    String addVArrayId = addVArraysIterForvNas.next();
                    if ((currentAssignmentsForvNas != null) && (currentAssignmentsForvNas.contains(addVArrayId))) {
                        // Just ignore those already assigned
                        _log.info("Virtual Nas already assigned to virtual array {}", addVArrayId);
                        continue;
                    }
                    varraysAddedTovNas.add(addVArrayId);
                    _log.info("virtual nas will be assigned to virtual array {}", addVArrayId);
                }
                if (!varraysAddedTovNas.isEmpty()) {
                    vNas.addAssignedVirtualArrays(varraysAddedTovNas);
                    _log.info("virtual nas assigned with virtual arrays size {}", varraysAddedTovNas.size());
                    varraysForvNasUpdated = true;
                }
            }
        }
        if (removeAssignments != null) {
            Set<String> removeVArrays = removeAssignments.getVarrays();
            if ((removeVArrays != null) && (!removeVArrays.isEmpty())) {
                // Iterate over the virtual arrays and assign them
                // to the virtual NAS.
                _log.info("Virtual Nas that has virtual array to remove {}", removeVArrays.toString());
                Iterator<String> removeVArraysIterForvNas = removeVArrays.iterator();
                while (removeVArraysIterForvNas.hasNext()) {
                    String removeVArrayId = removeVArraysIterForvNas.next();
                    if ((currentAssignmentsForvNas != null) && (!currentAssignmentsForvNas.contains(removeVArrayId))) {
                        // Just ignore those already assigned
                        _log.info("Virtual Nas not assigned to virtual array {}", removeVArrayId);
                        continue;
                    }
                    varraysRemovedFromvNas.add(removeVArrayId);
                    _log.info("virtual nas will be unassigned to virtual array {}", removeVArrayId);
                }
                if (!varraysRemovedFromvNas.isEmpty()) {
                    vNas.removeAssignedVirtualArrays(varraysRemovedFromvNas);
                    _log.info("virtual nas un-assigned with virtual arrays size {}", varraysRemovedFromvNas.size());
                    varraysForvNasUpdated = true;
                }
            }
        }
    } else {
        _log.info("Ignored assignment of varray to virtual nas as the storage port not belongs to vnx file");
    }
    if (varraysForvNasUpdated) {
        _dbClient.persistObject(vNas);
    }
    return varraysForvNasUpdated;
}
Also used : VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) StringSet(com.emc.storageos.db.client.model.StringSet) MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) VirtualArrayAssignments(com.emc.storageos.model.pools.VirtualArrayAssignments) HashSet(java.util.HashSet)

Example 32 with StoragePort

use of com.emc.storageos.db.client.model.StoragePort in project coprhd-controller by CoprHD.

the class StoragePortService method queryRegisteredResource.

/**
 * Gets the storage port with the passed id from the database.
 *
 * @param id the URN of a ViPR storage port.
 *
 * @return A reference to the registered StoragePool.
 *
 * @throws BadRequestException When the storage port is not registered.
 */
protected StoragePort queryRegisteredResource(URI id) {
    ArgValidator.checkUri(id);
    StoragePort port = _dbClient.queryObject(StoragePort.class, id);
    ArgValidator.checkEntity(port, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(port.getRegistrationStatus())) {
        throw APIException.badRequests.resourceNotRegistered(StoragePort.class.getSimpleName(), id);
    }
    return port;
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort)

Example 33 with StoragePort

use of com.emc.storageos.db.client.model.StoragePort in project coprhd-controller by CoprHD.

the class StoragePortService method getStoragePorts.

/**
 * Gets the ids and self links for all storage ports.
 *
 * @brief List storage ports
 * @return A StoragePortList reference specifying the ids and self links for
 *         the storage ports.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StoragePortList getStoragePorts() {
    StoragePortList storagePorts = new StoragePortList();
    List<URI> ids = _dbClient.queryByType(StoragePort.class, true);
    for (URI id : ids) {
        StoragePort port = _dbClient.queryObject(StoragePort.class, id);
        if ((port != null)) {
            storagePorts.getPorts().add(toNamedRelatedResource(port, port.getNativeGuid()));
        }
    }
    return storagePorts;
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) StoragePortList(com.emc.storageos.model.ports.StoragePortList) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 34 with StoragePort

use of com.emc.storageos.db.client.model.StoragePort in project coprhd-controller by CoprHD.

the class StoragePortService method queryResource.

@Override
protected StoragePort queryResource(URI id) {
    ArgValidator.checkUri(id);
    StoragePort port = _dbClient.queryObject(StoragePort.class, id);
    ArgValidator.checkEntity(port, id, isIdEmbeddedInURL(id));
    return port;
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort)

Example 35 with StoragePort

use of com.emc.storageos.db.client.model.StoragePort 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);
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) Network(com.emc.storageos.db.client.model.Network) MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

StoragePort (com.emc.storageos.db.client.model.StoragePort)477 URI (java.net.URI)285 ArrayList (java.util.ArrayList)261 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)143 HashMap (java.util.HashMap)134 List (java.util.List)130 NetworkLite (com.emc.storageos.util.NetworkLite)110 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)107 StringSet (com.emc.storageos.db.client.model.StringSet)92 PortAllocationContext (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)84 HashSet (java.util.HashSet)81 Initiator (com.emc.storageos.db.client.model.Initiator)78 Map (java.util.Map)64 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)62 StoragePool (com.emc.storageos.db.client.model.StoragePool)51 IOException (java.io.IOException)48 StringMap (com.emc.storageos.db.client.model.StringMap)45 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)43 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)42 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)34