use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.
the class DataDomainClient method getResponseObject.
private <T> T getResponseObject(Class<T> clazz, ClientResponse response) throws DataDomainApiException {
try {
JSONObject resp = response.getEntity(JSONObject.class);
T respObject = new Gson().fromJson(SecurityUtils.sanitizeJsonString(resp.toString()), clazz);
/*
* ObjectMapper mapper = new ObjectMapper();
* mapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
* mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
* T respObject = mapper.readValue(response.getEntity(String.class),clazz);
*/
return respObject;
} catch (Exception e) {
throw DataDomainApiException.exceptions.jsonWriterReaderException(e);
}
}
use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.
the class DataDomainClient method checkResponse.
private int checkResponse(URI uri, ClientResponse response) throws DataDomainApiException {
int errorCode = response.getStatus();
if (errorCode >= LOWEST_ERROR_STATUS) {
JSONObject obj = null;
String msg;
int ddCode;
try {
obj = response.getEntity(JSONObject.class);
msg = obj.getString(DataDomainApiConstants.DETAILS);
ddCode = obj.getInt(DataDomainApiConstants.CODE);
} catch (Exception e) {
throw DataDomainApiException.exceptions.jsonWriterReaderException(e);
}
log.error(String.format("DataDomain Rest API failed, DDCode: %d, Msg : %s", ddCode, msg));
if (ddCode == 404 || ddCode == 410) {
throw DataDomainResourceNotFoundException.notFound.resourceNotFound(uri.toString(), msg);
} else {
throw DataDomainApiException.exceptions.failedResponseFromDataDomainMsg(uri, errorCode, msg, ddCode);
}
} else {
return errorCode;
}
}
use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.
the class DataDomainFileStorageDevice method doConnect.
@Override
public void doConnect(StorageSystem storage) {
try {
_log.info("doConnect {} - start", storage.getId());
DataDomainClient ddClient = getDataDomainClient(storage);
if (ddClient == null) {
_log.error("doConnect failed, provider unreachable");
String sys = storage.getLabel() + "(" + storage.getIpAddress() + ")";
throw DataDomainApiException.exceptions.connectStorageFailed(sys);
}
DDMCInfoDetail ddInfo = ddClient.getManagementSystemInfo();
String msg = String.format("doConnect %1$s - complete", ddInfo);
_log.info(msg);
} catch (DataDomainApiException e) {
_log.error("doConnect failed.", e);
throw DeviceControllerException.exceptions.connectStorageFailed(e);
}
}
use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.
the class DataDomainFileStorageDevice method deleteExportRules.
@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) {
try {
// TODO - These lines may be removed once DD snapshot APIs become available.
if (!args.getFileOperation()) {
// Snapshot Export operation is not supported by Data Domain.
ServiceError serviceError = DeviceControllerErrors.datadomain.operationNotSupported();
serviceError.setMessage("Data Domain does not support snapshot export");
return BiosCommandResult.createErrorResult(serviceError);
}
_log.info("DataDomainFileStorageDevice deleteExportRules - start");
FileShare fs = args.getFs();
// List of existing export rules
List<ExportRule> existingExports = args.getExistingDBExportRules();
if ((existingExports == null) || (existingExports.isEmpty())) {
_log.info("Export rule delete, file system {} does not have an existing export to delete", args.getFsId());
return BiosCommandResult.createSuccessfulResult();
}
_log.info("Number of existng Rules found {}", existingExports.size());
// Build export path, adding sub-directory if not null and non-empty
String exportPath;
String subDir = args.getSubDirectory();
StringBuilder expPath = new StringBuilder();
if (!args.getFileOperation()) {
expPath.append(args.getSnapshotPath());
} else {
expPath.append(args.getFs().getPath());
}
if ((subDir != null) && (subDir.length() > 0)) {
expPath.append("/");
expPath.append(subDir);
}
exportPath = expPath.toString();
// Data Domain attaches a prefix to every file system path
expPath = new StringBuilder();
if (!exportPath.startsWith(DataDomainApiConstants.FS_PATH_BASE)) {
expPath.append(DataDomainApiConstants.FS_PATH_BASE);
}
expPath.append(exportPath);
_log.info("exportPath : {}", expPath);
args.setExportPath(expPath.toString());
for (ExportRule expRule : existingExports) {
if (expRule.getExportPath().equals(expPath.toString())) {
args.setObjIdOnDevice(expRule.getDeviceExportId());
break;
}
}
// Do we need to delete all subdirectories as well?
boolean allDirs = args.isAllDir();
// List of IDs of exports to delete
List<String> exportIdsToDelete = new ArrayList<>();
exportIdsToDelete.add(args.getObjIdOnDevice());
DataDomainClient ddClient = getDataDomainClient(storage);
if (ddClient == null) {
_log.error("deleteExportRules failed, provider unreachable");
String op = "Delete export rules";
return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
}
URI storagePoolId = args.getFs().getPool();
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
if (allDirs) {
// Add to the list of IDs of exports to delete
buildListOfIdsToDelete(ddClient, storagePool.getNativeId(), expPath.toString(), exportIdsToDelete);
}
doDeleteExports(ddClient, storagePool.getNativeId(), exportIdsToDelete);
_log.info("DataDomainFileStorageDevice deleteExportRules {} - complete", args.getFsId());
return BiosCommandResult.createSuccessfulResult();
} catch (DataDomainApiException dde) {
_log.error("Export update failed, device error:", dde);
return BiosCommandResult.createErrorResult(dde);
}
}
use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.
the class DataDomainFileStorageDevice method doShare.
@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
try {
_log.info("DataDomainFileStorageDevice doShare() - start");
DataDomainClient ddClient = getDataDomainClient(storage);
if (ddClient == null) {
_log.error("doShare failed, provider unreachable");
String op = "FS share create";
return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
}
// Check if this is a new share or update of the existing share
SMBShareMap smbShareMap = args.getFileObjShares();
SMBFileShare existingShare = (smbShareMap == null) ? null : smbShareMap.get(smbFileShare.getName());
String shareId;
DDShareInfo ddShareInfo;
// Cannot send empty description, send the share name in that case
if (smbFileShare.getDescription() == null || smbFileShare.getDescription().isEmpty()) {
_log.debug("SMB Share creation was called with empty description and setting name as desc");
smbFileShare.setDescription(smbFileShare.getName());
}
if (existingShare != null) {
shareId = existingShare.getNativeId();
// modify share
URI storagePoolId = args.getFs().getPool();
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
DDShareInfoDetail ddShareInfoDetail = ddClient.getShare(storagePool.getNativeId(), shareId);
if (ddShareInfoDetail.getPathStatus() == 0) {
DDServiceStatus ddSvcStatus = ddClient.deleteShare(storagePool.getNativeId(), shareId);
throw DataDomainApiException.exceptions.failedSharePathDoesNotExist(ddShareInfoDetail.getPath());
}
ddShareInfo = ddClient.modifyShare(storagePool.getNativeId(), shareId, smbFileShare.getDescription());
} else {
// new share
URI storagePoolId = args.getFs().getPool();
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
ddCreateShare(ddClient, storagePool.getNativeId(), smbFileShare, smbFileShare.getPath());
}
// init file share map
if (args.getFileObjShares() == null) {
args.initFileObjShares();
}
args.getFileObjShares().put(smbFileShare.getName(), smbFileShare);
_log.info("DataDomainFileStorageDevice doShare() - complete");
// Set MountPoint
smbFileShare.setMountPoint(smbFileShare.getStoragePortNetworkId(), smbFileShare.getStoragePortName(), smbFileShare.getName());
return BiosCommandResult.createSuccessfulResult();
} catch (DataDomainApiException e) {
_log.error("doShare failed, device error.", e);
return BiosCommandResult.createErrorResult(e);
}
}
Aggregations