Search in sources :

Example 6 with VirtualNAS

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

the class StoragePortAssociationHelper method getVNasNetworksMap.

/**
 * Gets the networks of the virtual nas and organized in a map.
 * This code assumes that an end point exists in one and only one network.
 *
 * @param sports the ports
 * @param dbClient an instance of {@link DbClient}
 * @return a map of networks and the virtual nas that are associated to them.
 */
private static Map<String, List<NetworkLite>> getVNasNetworksMap(Collection<StoragePort> sports, DbClient dbClient) {
    Map<String, List<NetworkLite>> vNasNetwork = new HashMap<>();
    NetworkLite network;
    List<VirtualNAS> vNasList = null;
    List<NetworkLite> list = null;
    for (StoragePort sport : sports) {
        if (TransportType.IP.name().equalsIgnoreCase(sport.getTransportType())) {
            StorageSystem system = dbClient.queryObject(StorageSystem.class, sport.getStorageDevice());
            if (DiscoveredDataObject.Type.vnxfile.name().equals(system.getSystemType()) || DiscoveredDataObject.Type.isilon.name().equals(system.getSystemType()) || DiscoveredDataObject.Type.unity.name().equals(system.getSystemType())) {
                network = NetworkUtil.getEndpointNetworkLite(sport.getPortNetworkId(), dbClient);
                vNasList = getStoragePortVirtualNAS(sport, dbClient);
                if (network != null && network.getInactive() == false && network.getTransportType().equals(sport.getTransportType()) && vNasList != null && !vNasList.isEmpty()) {
                    for (VirtualNAS vNas : vNasList) {
                        list = vNasNetwork.get(vNas.getNativeGuid());
                        if (list == null) {
                            list = new ArrayList<NetworkLite>();
                            vNasNetwork.put(vNas.getNativeGuid(), list);
                        }
                        list.add(network);
                    }
                }
            }
        }
    }
    return vNasNetwork;
}
Also used : VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 7 with VirtualNAS

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

the class StoragePortAssociationHelper method findvNasByNativeId.

/**
 * it return VirtualNAS from database using NativeId
 *
 * @param nativeId
 * @param dbClient
 * @return VirtualNAS based on nativeId
 */
private static VirtualNAS findvNasByNativeId(String nativeId, DbClient dbClient) {
    URIQueryResultList results = new URIQueryResultList();
    VirtualNAS vNas = null;
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualNASByNativeGuidConstraint(nativeId), results);
    Iterator<URI> iter = results.iterator();
    while (iter.hasNext()) {
        VirtualNAS tmpVnas = dbClient.queryObject(VirtualNAS.class, iter.next());
        if (tmpVnas != null && !tmpVnas.getInactive()) {
            vNas = tmpVnas;
            _log.info("found virtual NAS {}", tmpVnas.getNativeGuid() + ":" + tmpVnas.getNasName());
            break;
        }
    }
    return vNas;
}
Also used : VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 8 with VirtualNAS

use of com.emc.storageos.db.client.model.VirtualNAS 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 9 with VirtualNAS

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

the class StorageSystemService method getVnasServers.

/**
 * Gets all virtual NAS for the registered storage system with the passed
 * id.
 *
 * @param id the URN of a ViPR storage system.
 *
 * @brief List storage system virtual nas servers
 * @return A reference to a StoragePooList specifying the id and self link
 *         for each storage pool.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/vnasservers")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public VirtualNASList getVnasServers(@PathParam("id") URI id) {
    // Make sure storage system is registered.
    ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
    StorageSystem system = queryResource(id);
    ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
    VirtualNASList vNasList = new VirtualNASList();
    URIQueryResultList vNasURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceVirtualNasConstraint(id), vNasURIs);
    Iterator<URI> vNasIter = vNasURIs.iterator();
    while (vNasIter.hasNext()) {
        URI vNasURI = vNasIter.next();
        VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, vNasURI);
        if (vNas != null && !vNas.getInactive()) {
            vNasList.getVNASServers().add(toNamedRelatedResource(vNas, vNas.getNativeGuid()));
        }
    }
    return vNasList;
}
Also used : VirtualNASList(com.emc.storageos.model.vnas.VirtualNASList) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 10 with VirtualNAS

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

the class ProjectService method unassignVNasServersFromProject.

/**
 * Unassigns VNAS server from project.
 *
 * @param id the URN of a ViPR Project
 * @param param Assign virtual NAS server parameters
 * @prereq none
 * @brief Unassign VNAS servers from project
 * @return No data returned in response body
 * @throws BadRequestException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/unassign-vnas-servers")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ALL, ACL.OWN })
public Response unassignVNasServersFromProject(@PathParam("id") URI id, VirtualNasParam param) {
    checkCompatibleVersion();
    Project project = getProjectById(id, true);
    Set<String> vNasIds = param.getVnasServers();
    if (vNasIds != null && !vNasIds.isEmpty()) {
        StringSet vnasServers = project.getAssignedVNasServers();
        if (!vnasServers.containsAll(vNasIds)) {
            throw APIException.badRequests.vNasServersNotAssociatedToProject();
        }
        if (vnasServers != null && !vnasServers.isEmpty()) {
            for (String vId : vNasIds) {
                URI vnasURI = URI.create(vId);
                VirtualNAS vnas = _permissionsHelper.getObjectById(vnasURI, VirtualNAS.class);
                ArgValidator.checkEntity(vnas, vnasURI, isIdEmbeddedInURL(vnasURI));
                if (vnasServers.contains(vId)) {
                    vnas.dissociateProject(id.toString());
                    _dbClient.updateObject(vnas);
                    project.getAssignedVNasServers().remove(vId);
                }
            }
            _dbClient.updateObject(project);
            _log.info("Successfully unassigned the VNAS servers from project : {} ", project.getLabel());
        } else {
            throw APIException.badRequests.noVNasServersAssociatedToProject(project.getLabel());
        }
    } else {
        throw APIException.badRequests.invalidEntryForProjectVNAS();
    }
    return Response.ok().build();
}
Also used : MapProject(com.emc.storageos.api.mapper.functions.MapProject) Project(com.emc.storageos.db.client.model.Project) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

VirtualNAS (com.emc.storageos.db.client.model.VirtualNAS)54 URI (java.net.URI)26 ArrayList (java.util.ArrayList)19 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)18 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)16 StringSet (com.emc.storageos.db.client.model.StringSet)15 PhysicalNAS (com.emc.storageos.db.client.model.PhysicalNAS)9 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)9 List (java.util.List)9 StoragePort (com.emc.storageos.db.client.model.StoragePort)8 URISyntaxException (java.net.URISyntaxException)8 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)7 FileDeviceInputOutput (com.emc.storageos.volumecontroller.FileDeviceInputOutput)7 Project (com.emc.storageos.db.client.model.Project)6 StringMap (com.emc.storageos.db.client.model.StringMap)6 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)6 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)6 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)6 ControllerException (com.emc.storageos.volumecontroller.ControllerException)6