Search in sources :

Example 11 with DataDomainApiException

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);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Gson(com.google.gson.Gson) DataDomainResourceNotFoundException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException)

Example 12 with DataDomainApiException

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;
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) DataDomainResourceNotFoundException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException)

Example 13 with DataDomainApiException

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);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) DDMCInfoDetail(com.emc.storageos.datadomain.restapi.model.DDMCInfoDetail) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient)

Example 14 with DataDomainApiException

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) URI(java.net.URI) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) ExportRule(com.emc.storageos.model.file.ExportRule)

Example 15 with DataDomainApiException

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);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) StoragePool(com.emc.storageos.db.client.model.StoragePool) DDShareInfoDetail(com.emc.storageos.datadomain.restapi.model.DDShareInfoDetail) DDServiceStatus(com.emc.storageos.datadomain.restapi.model.DDServiceStatus) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) URI(java.net.URI) DDShareInfo(com.emc.storageos.datadomain.restapi.model.DDShareInfo)

Aggregations

DataDomainApiException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException)20 DataDomainClient (com.emc.storageos.datadomain.restapi.DataDomainClient)13 DataDomainResourceNotFoundException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException)10 URI (java.net.URI)10 ArrayList (java.util.ArrayList)9 StoragePool (com.emc.storageos.db.client.model.StoragePool)8 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)5 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)5 IOException (java.io.IOException)5 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)4 UnManagedFileSystem (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)4 DDMTreeInfo (com.emc.storageos.datadomain.restapi.model.DDMTreeInfo)3 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)3 FileExport (com.emc.storageos.db.client.model.FileExport)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 HashMap (java.util.HashMap)3 DDExportInfo (com.emc.storageos.datadomain.restapi.model.DDExportInfo)2