Search in sources :

Example 76 with ExportGroup

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

the class ExportRemoveVolumesOnAdoptedMaskCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        URI exportMaskUri = getMask();
        ExportMask exportMask = (exportMaskUri != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
        ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
        for (URI volumeURI : _volumes) {
            BlockObject volume = BlockObject.fetch(dbClient, volumeURI);
            if (exportMask != null && status == Operation.Status.ready) {
                exportMask.removeFromUserCreatedVolumes(volume);
                exportMask.removeVolume(volume.getId());
            }
        }
        if (exportMask != null) {
            URI pgURI = exportMask.getPortGroup();
            if (exportMask.getVolumes() == null || exportMask.getVolumes().isEmpty()) {
                exportGroup.removeExportMask(exportMask.getId());
                dbClient.markForDeletion(exportMask);
                dbClient.updateObject(exportGroup);
            } else {
                dbClient.updateObject(exportMask);
            }
            updatePortGroupVolumeCount(pgURI, dbClient);
        }
        _log.info(String.format("Done ExportMaskRemoveVolume - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
    } catch (Exception e) {
        _log.error(String.format("Failed updating status for ExportMaskRemoveVolume - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 77 with ExportGroup

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

the class RollbackExportGroupCreateCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
        ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
        if ((status == Operation.Status.error) && (coded instanceof ServiceError)) {
            ServiceError error = (ServiceError) coded;
            String originalMessage = error.getMessage();
            StorageSystem storageSystem = exportMask != null ? dbClient.queryObject(StorageSystem.class, exportMask.getStorageDevice()) : null;
            String additionMessage = String.format("Rollback encountered problems cleaning up export mask %s on storage system %s and may require manual clean up", exportMask.getMaskName(), storageSystem != null ? storageSystem.forDisplay() : "Unknown");
            String updatedMessage = String.format("%s\n%s", originalMessage, additionMessage);
            error.setMessage(updatedMessage);
        }
        if (exportMask != null) {
            URI pgURI = exportMask.getPortGroup();
            // clean up export group
            exportGroup.removeExportMask(exportMask.getId());
            dbClient.updateObject(exportGroup);
            // if its not used anywhere and is system created delete it
            if (ExportMaskUtils.getExportGroups(dbClient, exportMask.getId()).isEmpty() && exportMask.getCreatedBySystem()) {
                dbClient.markForDeletion(exportMask);
            }
            updatePortGroupVolumeCount(pgURI, dbClient);
        }
        _log.info(String.format("Done RollbackExportGroupCreate - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
    } catch (Exception e) {
        _log.error(String.format("Failed updating status for RollbackExportGroupCreate - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 78 with ExportGroup

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

the class ExportTaskCompleter method recordBlockExportOperation.

/**
 * Record block export group related event and audit
 *
 * @param dbClient db client
 * @param opType operation type
 * @param status operation status
 * @param evDesc event description
 * @param extParam parameters array from which we could generate detail
 *            audit message
 */
public void recordBlockExportOperation(DbClient dbClient, OperationTypeEnum opType, Operation.Status status, String evDesc, Object... extParam) {
    try {
        boolean opStatus = (Operation.Status.ready == status);
        String evType;
        evType = opType.getEvType(opStatus);
        String opStage = AuditLogManager.AUDITOP_END;
        _logger.info("opType: {} detail: {}", opType.toString(), evType + ':' + evDesc);
        ExportGroup exportGroup = (ExportGroup) extParam[0];
        recordBlockExportEvent(dbClient, exportGroup.getId(), evType, status, evDesc);
        switch(opType) {
            case CREATE_EXPORT_GROUP:
            case UPDATE_EXPORT_GROUP:
            case DELETE_EXPORT_GROUP:
            case EXPORT_PATH_ADJUSTMENT:
            case EXPORT_CHANGE_PORT_GROUP:
                AuditBlockUtil.auditBlock(dbClient, opType, opStatus, opStage, exportGroup.getLabel(), exportGroup.getId().toString(), exportGroup.getVirtualArray().toString(), exportGroup.getProject().toString());
                break;
            case ADD_EXPORT_INITIATOR:
            case DELETE_EXPORT_INITIATOR:
                Initiator initiator = (Initiator) extParam[1];
                AuditBlockUtil.auditBlock(dbClient, opType, opStatus, opStage, initiator.getProtocol(), initiator.getInitiatorNode(), initiator.getInitiatorPort(), initiator.getHostName(), exportGroup.getLabel(), exportGroup.getId().toString());
                break;
            case ADD_EXPORT_VOLUME:
            case DELETE_EXPORT_VOLUME:
                BlockObject bo = (BlockObject) extParam[1];
                AuditBlockUtil.auditBlock(dbClient, opType, opStatus, opStage, bo.getId().toString(), exportGroup.getLabel(), exportGroup.getId().toString());
                break;
            default:
                _logger.error("unrecognized block export operation type");
        }
        _logger.info(String.format("ExportGroup after %s Operation%n%s", opType, exportGroup.toString()));
    } catch (Exception e) {
        _logger.error("Failed to record block export operation {}, err: {}", opType.toString(), e);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 79 with ExportGroup

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

the class ExportTaskCompleter method recordBlockExportEvent.

/**
 * @param dbClient
 * @param evtType
 * @param status
 * @param desc
 * @throws Exception
 */
public void recordBlockExportEvent(DbClient dbClient, URI uri, String evtType, Operation.Status status, String desc) throws Exception {
    RecordableEventManager eventManager = new RecordableEventManager();
    eventManager.setDbClient(dbClient);
    ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, uri);
    RecordableBourneEvent event = ControllerUtils.convertToRecordableBourneEvent(exportGroup, evtType, desc, "", dbClient, ControllerUtils.BLOCK_EVENT_SERVICE, RecordType.Event.name(), ControllerUtils.BLOCK_EVENT_SOURCE);
    try {
        eventManager.recordEvents(event);
        _logger.info("Bourne {} event recorded", evtType);
    } catch (Exception ex) {
        _logger.error("Failed to record event. Event description: {}. Error: ", evtType, ex);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) RecordableBourneEvent(com.emc.storageos.volumecontroller.impl.monitoring.RecordableBourneEvent) RecordableEventManager(com.emc.storageos.volumecontroller.impl.monitoring.RecordableEventManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 80 with ExportGroup

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

the class ExportGroupService method buildExportGroupSearchResponse.

/**
 * Build search response based on query result.
 *
 * @param exportGroups from query
 * @param resRepLists result
 * @param selfOnly true or false
 * @param type Cluster, Host or Initiator
 */
private void buildExportGroupSearchResponse(List<ExportGroup> exportGroups, List<SearchResultResourceRep> resRepLists, boolean selfOnly, String type, boolean authorized) {
    PermissionsEnforcingResourceFilter<ExportGroup> filter = new ExportGroupSearchFilter(getUserFromContext(), _permissionsHelper);
    for (ExportGroup eg : exportGroups) {
        if (!authorized && !filter.isExposed(eg)) {
            // authorization failed, don't add to search result
            continue;
        }
        if (selfOnly) {
            if (!eg.getType().equals(type)) {
                // match invalid, only return matching types, process next
                continue;
            }
        }
        RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), eg.getId()));
        SearchResultResourceRep searchResult = new SearchResultResourceRep(eg.getId(), selfLink, eg.getLabel());
        resRepLists.add(searchResult);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) RestLinkRep(com.emc.storageos.model.RestLinkRep)

Aggregations

ExportGroup (com.emc.storageos.db.client.model.ExportGroup)278 URI (java.net.URI)206 ArrayList (java.util.ArrayList)139 ExportMask (com.emc.storageos.db.client.model.ExportMask)138 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)111 HashMap (java.util.HashMap)94 Initiator (com.emc.storageos.db.client.model.Initiator)86 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)84 NamedURI (com.emc.storageos.db.client.model.NamedURI)80 HashSet (java.util.HashSet)70 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)63 Workflow (com.emc.storageos.workflow.Workflow)61 List (java.util.List)59 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)55 BlockObject (com.emc.storageos.db.client.model.BlockObject)49 Map (java.util.Map)47 ExportOrchestrationTask (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)44 ControllerException (com.emc.storageos.volumecontroller.ControllerException)41 StringSet (com.emc.storageos.db.client.model.StringSet)38 StringMap (com.emc.storageos.db.client.model.StringMap)33