Search in sources :

Example 11 with Operation

use of com.emc.storageos.db.client.model.Operation 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);
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) Network(com.emc.storageos.db.client.model.Network) NetworkSystemList(com.emc.storageos.model.network.NetworkSystemList) List(java.util.List) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 12 with Operation

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

the class NetworkSystemService method addSanZones.

/**
 * Adds one or more SAN zones to the active zoneset of the VSAN or fabric specified on a network system.
 * This is an asynchronous call.
 *
 * @param sanZones A parameter structure listing the zone(s) to be added and their members.
 * @param id the URN of a ViPR network system.
 * @param fabricId The name of the VSAN or fabric as returned by
 *            /vdc/network-systems/{id}/san-fabrics or the VSAN or fabric WWN
 * @prereq none
 * @brief Add SAN zones to network system VSAN or fabric
 * @return A task description structure.
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-fabrics/{fabricId}/san-zones")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep addSanZones(SanZoneCreateParam sanZones, @PathParam("id") URI id, @PathParam("fabricId") String fabricId) throws InternalException {
    String task = UUID.randomUUID().toString();
    String fabricWwn = null;
    if (WWNUtility.isValidWWN(fabricId)) {
        fabricWwn = fabricId;
        fabricId = fabricId.replaceAll(":", "");
    }
    ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
    NetworkSystem device = queryResource(id);
    List<Zone> zones = new ArrayList<Zone>();
    for (SanZone sz : sanZones.getZones()) {
        Zone zone = new Zone(sz.getName());
        validateZoneName(sz.getName(), device.getSystemType());
        zones.add(zone);
        for (String szm : sz.getMembers()) {
            ZoneMember member = createZoneMember(szm);
            zone.getMembers().add(member);
        }
        ArgValidator.checkFieldNotEmpty(zone.getMembers(), "zone members");
        auditOp(OperationTypeEnum.ADD_SAN_ZONE, true, AuditLogManager.AUDITOP_BEGIN, zone.getName(), device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL(), device.getVersion(), device.getUptime());
    }
    ArgValidator.checkFieldNotEmpty(zones, "zones");
    Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, device.getId(), task, ResourceOperationTypeEnum.ADD_SAN_ZONE);
    NetworkController controller = getNetworkController(device.getSystemType());
    controller.addSanZones(device.getId(), fabricId, fabricWwn, zones, false, task);
    return toTask(device, task, op);
}
Also used : Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) SanZone(com.emc.storageos.model.network.SanZone) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) ArrayList(java.util.ArrayList) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) Operation(com.emc.storageos.db.client.model.Operation) SanZone(com.emc.storageos.model.network.SanZone) NetworkController(com.emc.storageos.networkcontroller.NetworkController) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 13 with Operation

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

the class RPBlockServiceApiImpl method createTaskForVolume.

/**
 * Used to create a task and add it to the TaskList
 *
 * @param volume
 *            Volume that the task is for
 * @param type
 *            type of the task
 * @param taskList
 *            The TaskList to store tasks
 * @param task
 *            Task Id
 */
private void createTaskForVolume(Volume volume, ResourceOperationTypeEnum type, TaskList taskList, String task) {
    // Create the OP
    Operation op = _dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, type);
    volume.setOpStatus(new OpStatusMap());
    volume.getOpStatus().put(task, op);
    // Persist the volume in the db
    _dbClient.updateObject(volume);
    _log.info(String.format("Created task of type [%s] for volume [%s]", type.name(), volume.getLabel()));
    // Create the task and add it to the task list
    taskList.getTaskList().add(toTask(volume, task, op));
}
Also used : OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation)

Example 14 with Operation

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

the class RPBlockServiceApiImpl method updateVolumesInVolumeGroup.

/**
 * {@inheritDoc}
 */
@Override
public void updateVolumesInVolumeGroup(VolumeGroupVolumeList addVolumes, List<Volume> removeVolumes, URI applicationId, String taskId) {
    VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, applicationId);
    ApplicationAddVolumeList addVolumeList = null;
    List<URI> removeVolumesURI = null;
    RPController controller = null;
    URI protSystemUri = null;
    Volume firstVolume = null;
    if (addVolumes != null && addVolumes.getVolumes() != null && !addVolumes.getVolumes().isEmpty()) {
        addVolumeList = addVolumesToApplication(addVolumes, volumeGroup);
        List<URI> vols = addVolumeList.getVolumes();
        if (vols != null && !vols.isEmpty()) {
            firstVolume = _dbClient.queryObject(Volume.class, vols.get(0));
        }
    }
    if (removeVolumes != null && !removeVolumes.isEmpty()) {
        removeVolumesURI = getValidVolumesToRemoveFromCG(removeVolumes);
        if (firstVolume == null) {
            firstVolume = removeVolumes.get(0);
        }
    }
    if ((addVolumeList != null && !addVolumeList.getVolumes().isEmpty()) || (removeVolumesURI != null && !removeVolumesURI.isEmpty())) {
        protSystemUri = firstVolume.getProtectionController();
        ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, protSystemUri);
        controller = getController(RPController.class, system.getSystemType());
        controller.updateApplication(protSystemUri, addVolumeList, removeVolumesURI, volumeGroup.getId(), taskId);
    } else {
        // No need to call to controller. update the application task
        Operation op = volumeGroup.getOpStatus().get(taskId);
        op.ready();
        volumeGroup.getOpStatus().updateTaskStatus(taskId, op);
        _dbClient.updateObject(volumeGroup);
    }
}
Also used : ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) RPController(com.emc.storageos.protectioncontroller.RPController) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Example 15 with Operation

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

the class RPBlockServiceApiImpl method createVolumes.

@Override
public TaskList createVolumes(VolumeCreate param, Project project, VirtualArray varray, VirtualPool vpool, Map<VpoolUse, List<Recommendation>> recommendationMap, TaskList taskList, String task, VirtualPoolCapabilityValuesWrapper capabilities) throws InternalException {
    List<Recommendation> recommendations = recommendationMap.get(VpoolUse.ROOT);
    // List of volumes to be prepared
    List<URI> volumeURIs = new ArrayList<URI>();
    // Volume label from the param
    String volumeLabel = param.getName();
    // List to store the volume descriptors for the Block Orchestration
    List<VolumeDescriptor> volumeDescriptors = new ArrayList<VolumeDescriptor>();
    // Store capabilities of the CG, so they make it down to the controller
    if (vpool.getRpCopyMode() != null) {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.RP_COPY_MODE, vpool.getRpCopyMode());
    }
    if (vpool.getRpRpoType() != null && NullColumnValueGetter.isNotNullValue(vpool.getRpRpoType())) {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.RP_RPO_TYPE, vpool.getRpRpoType());
    }
    if (vpool.checkRpRpoValueSet()) {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.RP_RPO_VALUE, vpool.getRpRpoValue());
    }
    // Get the first recommendation, we need to figure out if this is a change vpool
    RPProtectionRecommendation rpProtectionRec = (RPProtectionRecommendation) recommendations.get(0);
    boolean isChangeVpool = (rpProtectionRec.getVpoolChangeVolume() != null);
    boolean isChangeVpoolForProtectedVolume = rpProtectionRec.isVpoolChangeProtectionAlreadyExists();
    // for change vpool, save off the original source volume in case we need to roll back
    URI oldVpoolId = null;
    if (isChangeVpool || isChangeVpoolForProtectedVolume) {
        Volume changeVpoolVolume = _dbClient.queryObject(Volume.class, rpProtectionRec.getVpoolChangeVolume());
        oldVpoolId = changeVpoolVolume.getVirtualPool();
    }
    try {
        // Prepare the volumes
        prepareRecommendedVolumes(param, task, taskList, project, varray, vpool, capabilities.getResourceCount(), recommendations, volumeLabel, capabilities, volumeDescriptors, volumeURIs);
        // Execute the volume creations requests for each recommendation.
        Iterator<Recommendation> recommendationsIter = recommendations.iterator();
        while (recommendationsIter.hasNext()) {
            RPProtectionRecommendation recommendation = (RPProtectionRecommendation) recommendationsIter.next();
            volumeDescriptors.addAll(createVolumeDescriptors(recommendation, volumeURIs, capabilities, oldVpoolId, param.getComputeResource()));
            logDescriptors(volumeDescriptors);
            BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
            // TODO might be able to use param.getSize() instead of the below code to find requestedVolumeCapactity
            Long requestedVolumeCapactity = 0L;
            for (URI volumeURI : volumeURIs) {
                Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
                if (Volume.PersonalityTypes.SOURCE.name().equalsIgnoreCase(volume.getPersonality())) {
                    requestedVolumeCapactity = volume.getCapacity();
                    break;
                }
            }
            computeProtectionCapacity(volumeURIs, requestedVolumeCapactity, false, isChangeVpool, null);
            if (isChangeVpool) {
                _log.info("Add Recoverpoint Protection to existing volume");
                controller.changeVirtualPool(volumeDescriptors, task);
            } else {
                _log.info("Create RP volumes");
                controller.createVolumes(volumeDescriptors, task);
            }
        }
    } catch (Exception e) {
        _log.error(e.getMessage(), e);
        try {
            // We want to return the volume back to its original state.
            if (isChangeVpool || isChangeVpoolForProtectedVolume) {
                Volume changeVpoolVolume = _dbClient.queryObject(Volume.class, rpProtectionRec.getVpoolChangeVolume());
                VirtualPool oldVpool = _dbClient.queryObject(VirtualPool.class, oldVpoolId);
                RPHelper.rollbackProtectionOnVolume(changeVpoolVolume, oldVpool, _dbClient);
            }
            for (URI volumeURI : volumeURIs) {
                // completely rollback an existing volume (which the change vpool volume would be).
                if (!volumeURI.equals(rpProtectionRec.getVpoolChangeVolume())) {
                    RPHelper.rollbackVolume(volumeURI, _dbClient);
                }
            }
        } catch (Exception e2) {
            // best effort for rollback; still need to set the tasks to error
            _log.error("rollback create volume or change vpool failed");
            _log.error(e2.getMessage(), e);
        }
        // Let's check to see if there are existing tasks, if so, put them in error.
        if (taskList.getTaskList() != null && !taskList.getTaskList().isEmpty()) {
            for (TaskResourceRep volumeTask : taskList.getTaskList()) {
                volumeTask.setState(Operation.Status.error.name());
                volumeTask.setMessage(e.getMessage());
                Operation statusUpdate = new Operation(Operation.Status.error.name(), e.getMessage());
                _dbClient.updateTaskOpStatus(Volume.class, volumeTask.getResource().getId(), task, statusUpdate);
            }
        }
        throw APIException.badRequests.rpBlockApiImplPrepareVolumeException(volumeLabel);
    }
    return taskList;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) BlockOrchestrationController(com.emc.storageos.blockorchestrationcontroller.BlockOrchestrationController) RPProtectionRecommendation(com.emc.storageos.volumecontroller.RPProtectionRecommendation) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Recommendation(com.emc.storageos.volumecontroller.Recommendation) RPRecommendation(com.emc.storageos.volumecontroller.RPRecommendation) RPProtectionRecommendation(com.emc.storageos.volumecontroller.RPProtectionRecommendation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) Volume(com.emc.storageos.db.client.model.Volume)

Aggregations

Operation (com.emc.storageos.db.client.model.Operation)272 URI (java.net.URI)114 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)105 Path (javax.ws.rs.Path)105 Produces (javax.ws.rs.Produces)103 Volume (com.emc.storageos.db.client.model.Volume)93 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)92 ArrayList (java.util.ArrayList)83 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)70 Consumes (javax.ws.rs.Consumes)70 NamedURI (com.emc.storageos.db.client.model.NamedURI)68 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)68 POST (javax.ws.rs.POST)67 TaskList (com.emc.storageos.model.TaskList)59 FileShare (com.emc.storageos.db.client.model.FileShare)56 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)49 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)40 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)36 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)35 ControllerException (com.emc.storageos.volumecontroller.ControllerException)35