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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations