use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class MigrationService method deleteMigration.
/**
* Delete a migration that has been committed or cancelled
*
* @param id the URN of a ViPR migration.
*
* @brief Delete a committed or cancelled migration.
* @return A TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteMigration(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, Migration.class, "id");
Migration migration = queryResource(id);
if (!BulkList.MigrationFilter.isUserAuthorizedForMigration(migration, getUserFromContext(), _permissionsHelper)) {
StorageOSUser user = getUserFromContext();
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
String status = migration.getMigrationStatus();
String migrationName = migration.getLabel();
if (status == null || status.isEmpty() || migrationName == null || migrationName.isEmpty()) {
throw APIException.badRequests.migrationHasntStarted(id.toString());
}
if (!status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.COMMITTED.getStatusValue()) && !status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.CANCELLED.getStatusValue()) && !status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.ERROR.getStatusValue())) {
throw VPlexApiException.exceptions.cantRemoveMigrationInvalidState(migrationName);
}
URI volId = migration.getVolume();
Volume vplexVol = _dbClient.queryObject(Volume.class, volId);
// Create a unique task id.
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Volume.class, volId, taskId, ResourceOperationTypeEnum.DELETE_MIGRATION);
TaskResourceRep task = toTask(vplexVol, taskId, op);
if (migration.getInactive()) {
s_logger.info("Migration {} has been deleted", id);
op.ready();
vplexVol.getOpStatus().createTaskStatus(taskId, op);
_dbClient.persistObject(vplexVol);
return task;
}
try {
VPlexController controller = _vplexBlockServiceApi.getController();
controller.deleteMigration(vplexVol.getStorageController(), id, taskId);
} catch (InternalException e) {
s_logger.error("Error", e);
String errMsg = String.format("Error: %s", e.getMessage());
task.setState(Operation.Status.error.name());
task.setMessage(errMsg);
op.error(e);
vplexVol.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.persistObject(vplexVol);
}
return task;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class MigrationService method resumeMigration.
/**
* Resume a migration that was previously paused.
*
* @prereq The migration is paused
*
* @param id the URN of a ViPR migration.
*
* @brief Resume a paused migration.
* @return A TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/resume")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep resumeMigration(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, Migration.class, "id");
Migration migration = queryResource(id);
if (!BulkList.MigrationFilter.isUserAuthorizedForMigration(migration, getUserFromContext(), _permissionsHelper)) {
StorageOSUser user = getUserFromContext();
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
String status = migration.getMigrationStatus();
String migrationName = migration.getLabel();
if (status == null || status.isEmpty() || migrationName == null || migrationName.isEmpty()) {
throw APIException.badRequests.migrationHasntStarted(id.toString());
}
if (!status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.PAUSED.getStatusValue())) {
throw APIException.badRequests.migrationCantBeResumed(migrationName, status);
}
URI volId = migration.getVolume();
Volume vplexVol = _dbClient.queryObject(Volume.class, volId);
// Create a unique task id.
String taskId = UUID.randomUUID().toString();
// Create a task for the virtual volume being migrated and set the
// initial task state to pending.
Operation op = _dbClient.createTaskOpStatus(Volume.class, volId, taskId, ResourceOperationTypeEnum.RESUME_MIGRATION);
TaskResourceRep task = toTask(vplexVol, taskId, op);
try {
VPlexController controller = _vplexBlockServiceApi.getController();
controller.resumeMigration(vplexVol.getStorageController(), id, taskId);
} catch (InternalException e) {
s_logger.error("Error", e);
String errMsg = String.format("Error: %s", e.getMessage());
task.setState(Operation.Status.error.name());
task.setMessage(errMsg);
op.error(e);
vplexVol.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.persistObject(vplexVol);
}
return task;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class MigrationService method cancelMigration.
/**
* Cancel a migration that has yet to be committed.
*
* @prereq none
*
* @param id the URN of a ViPR migration.
*
* @brief Cancel an uncommitted migration.
* @return A TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/cancel")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep cancelMigration(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, Migration.class, "id");
Migration migration = queryResource(id);
if (!BulkList.MigrationFilter.isUserAuthorizedForMigration(migration, getUserFromContext(), _permissionsHelper)) {
StorageOSUser user = getUserFromContext();
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
if (migration == null || migration.getInactive()) {
throw APIException.badRequests.cancelMigrationFailed(id.toString(), "The migration is invalid");
}
String status = migration.getMigrationStatus();
String migrationName = migration.getLabel();
URI volId = migration.getVolume();
Volume vplexVol = _dbClient.queryObject(Volume.class, volId);
if (vplexVol == null || vplexVol.getInactive()) {
throw APIException.badRequests.cancelMigrationFailed(migrationName, "The migrating volume is not valid");
}
// Don't allow cancel operation if the vplex volume is in a CG
URI cgURI = vplexVol.getConsistencyGroup();
if (!NullColumnValueGetter.isNullURI(cgURI)) {
throw APIException.badRequests.cancelMigrationFailed(migrationName, "Migration cancellation is not supported for the volumes in consistency group");
}
if (status == null || status.isEmpty() || migrationName == null || migrationName.isEmpty()) {
throw APIException.badRequests.migrationHasntStarted(id.toString());
}
if (status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.COMMITTED.getStatusValue())) {
throw APIException.badRequests.migrationCantBeCancelled(migrationName, status);
}
// Create a unique task id.
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Volume.class, volId, taskId, ResourceOperationTypeEnum.CANCEL_MIGRATION);
TaskResourceRep task = toTask(vplexVol, taskId, op);
if (status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.CANCELLED.getStatusValue()) || status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.PARTIALLY_CANCELLED.getStatusValue())) {
// it has been cancelled
s_logger.info("Migration {} has been cancelled", id);
op.ready();
vplexVol.getOpStatus().createTaskStatus(taskId, op);
_dbClient.persistObject(vplexVol);
return task;
}
try {
VPlexController controller = _vplexBlockServiceApi.getController();
controller.cancelMigration(vplexVol.getStorageController(), id, taskId);
} catch (InternalException e) {
s_logger.error("Controller Error", e);
String errMsg = String.format("Controller Error: %s", e.getMessage());
task.setState(Operation.Status.error.name());
task.setMessage(errMsg);
op.error(e);
vplexVol.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.persistObject(vplexVol);
}
return task;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class NetworkSystemService method removeSanZones.
/**
* Deletes one or more zone(s) from the active zoneset of the VSAN or fabric specified in
* the network system. This is an asynchronous call.
*
* @param sanZones A list of Zones and their zone members that should be deleted from
* the active zoneset. Note: the zone members must be included (deletion of a zone is based
* on matching both the name and the zone 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 Delete zones from 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/remove")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep removeSanZones(SanZonesDeleteParam 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);
Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, device.getId(), task, ResourceOperationTypeEnum.REMOVE_SAN_ZONE);
List<Zone> zones = new ArrayList<Zone>();
for (SanZone sz : sanZones.getZones()) {
Zone zone = new Zone(sz.getName());
zones.add(zone);
for (String szm : sz.getMembers()) {
ZoneMember member = createZoneMember(szm);
zone.getMembers().add(member);
}
auditOp(OperationTypeEnum.REMOVE_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");
NetworkController controller = getNetworkController(device.getSystemType());
controller.removeSanZones(device.getId(), fabricId, fabricWwn, zones, false, task);
return toTask(device, task, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class NetworkSystemService method updateAliases.
/**
* Changes the WWN member of one or more aliases on the specified network system. For Brocade
* the fabric of the aliases will be removed must be specified.
* For MDS, this input is ignored if provided.
* <p>
* Current address WWN is optional; however, if provided, it must match the one in system before update. If not, exception will be
* thrown.
* <p>
* This is an asynchronous call.
*
* @param aliases A parameter structure listing the aliases to be updated
* @param id the URN of a ViPR network system.
* @param fabricId The name of the VSAN or fabric. This parameter is ignored
* if network system is an MDS
* @prereq none
* @brief Update aliases in network system
* @return A task description structure.
* @throws InternalException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-aliases")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateAliases(WwnAliasUpdateParams updateAliasParam, @PathParam("id") URI id) throws InternalException {
String task = UUID.randomUUID().toString();
ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
ArgValidator.checkFieldNotEmpty(updateAliasParam.getUpdateAliases(), "aliases");
NetworkSystem device = queryResource(id);
String fabricId = updateAliasParam.getFabricId();
if (Type.brocade.toString().equals(device.getSystemType())) {
ArgValidator.checkFieldNotEmpty(fabricId, "fabric-id");
}
String fabricWwn = null;
if (WWNUtility.isValidWWN(fabricId)) {
fabricWwn = fabricId;
fabricId = fabricId.replaceAll(":", "");
}
Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, device.getId(), task, ResourceOperationTypeEnum.UPDATE_ALIAS);
List<ZoneWwnAliasUpdate> zoneAliasesUpdate = new ArrayList<ZoneWwnAliasUpdate>();
for (WwnAliasUpdateParam updateAlias : updateAliasParam.getUpdateAliases()) {
validateAlias(updateAlias, false);
// validate new address
if (!StringUtils.isEmpty(updateAlias.getNewAddress())) {
validateWWN(updateAlias.getNewAddress());
}
// validate new name
if (!StringUtils.isEmpty(updateAlias.getNewName())) {
validateWWNAlias(updateAlias.getNewName());
}
zoneAliasesUpdate.add(new ZoneWwnAliasUpdate(updateAlias.getName(), updateAlias.getNewName(), updateAlias.getNewAddress(), updateAlias.getAddress()));
auditOp(OperationTypeEnum.UPDATE_ALIAS, true, AuditLogManager.AUDITOP_BEGIN, updateAlias.getName(), device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL(), device.getVersion(), device.getUptime());
}
NetworkController controller = getNetworkController(device.getSystemType());
controller.updateAliases(device.getId(), fabricId, fabricWwn, zoneAliasesUpdate, task);
return toTask(device, task, op);
}
Aggregations