Search in sources :

Example 1 with ImageStoreDetailVO

use of com.cloud.storage.datastore.db.ImageStoreDetailVO in project cosmic by MissionCriticalCloud.

the class ImageStoreHelper method createImageStore.

public ImageStoreVO createImageStore(final Map<String, Object> params, final Map<String, String> details) {
    ImageStoreVO store = imageStoreDao.findByName((String) params.get("name"));
    if (store != null) {
        return store;
    }
    store = new ImageStoreVO();
    store.setProtocol((String) params.get("protocol"));
    store.setProviderName((String) params.get("providerName"));
    store.setScope((ScopeType) params.get("scope"));
    store.setDataCenterId((Long) params.get("zoneId"));
    final String uuid = (String) params.get("uuid");
    if (uuid != null) {
        store.setUuid(uuid);
    } else {
        store.setUuid(UUID.randomUUID().toString());
    }
    store.setUrl((String) params.get("url"));
    store.setName((String) params.get("name"));
    if (store.getName() == null) {
        store.setName(store.getUuid());
    }
    store.setRole((DataStoreRole) params.get("role"));
    if ("cifs".equalsIgnoreCase((String) params.get("protocol")) && details != null) {
        final String user = details.get("user");
        String password = details.get("password");
        final String domain = details.get("domain");
        String updatedPath = (String) params.get("url");
        if (user == null || password == null) {
            final String errMsg = "Missing cifs user and password details. Add them as details parameter.";
            throw new InvalidParameterValueException(errMsg);
        } else {
            try {
                password = DBEncryptionUtil.encrypt(URLEncoder.encode(password, "UTF-8"));
                details.put("password", password);
                updatedPath += "?user=" + user + "&password=" + password + "&domain=" + domain;
            } catch (final UnsupportedEncodingException e) {
                throw new CloudRuntimeException("Error while generating the cifs url. " + e.getMessage());
            }
            store.setUrl(updatedPath);
        }
    }
    store = imageStoreDao.persist(store);
    // persist details
    if (details != null) {
        final Iterator<String> keyIter = details.keySet().iterator();
        while (keyIter.hasNext()) {
            final String key = keyIter.next().toString();
            final ImageStoreDetailVO detail = new ImageStoreDetailVO();
            detail.setStoreId(store.getId());
            detail.setName(key);
            String value = details.get(key);
            // encrypt swift key or s3 secret key
            if (key.equals(ApiConstants.KEY)) {
                value = DBEncryptionUtil.encrypt(value);
            }
            detail.setValue(value);
            imageStoreDetailsDao.persist(detail);
        }
    }
    return store;
}
Also used : ImageStoreDetailVO(com.cloud.storage.datastore.db.ImageStoreDetailVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 2 with ImageStoreDetailVO

use of com.cloud.storage.datastore.db.ImageStoreDetailVO in project cosmic by MissionCriticalCloud.

the class ImageStoreDetailsDaoImpl method getDetails.

@Override
public Map<String, String> getDetails(final long storeId) {
    final SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create();
    sc.setParameters("store", storeId);
    final List<ImageStoreDetailVO> details = listBy(sc);
    final Map<String, String> detailsMap = new HashMap<>();
    for (final ImageStoreDetailVO detail : details) {
        final String name = detail.getName();
        String value = detail.getValue();
        if (name.equals(ApiConstants.KEY)) {
            value = DBEncryptionUtil.decrypt(value);
        }
        detailsMap.put(name, value);
    }
    return detailsMap;
}
Also used : ImageStoreDetailVO(com.cloud.storage.datastore.db.ImageStoreDetailVO) HashMap(java.util.HashMap)

Example 3 with ImageStoreDetailVO

use of com.cloud.storage.datastore.db.ImageStoreDetailVO in project cosmic by MissionCriticalCloud.

the class ImageStoreDetailsDaoImpl method deleteDetails.

@Override
public void deleteDetails(final long storeId) {
    final SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create();
    sc.setParameters("store", storeId);
    final List<ImageStoreDetailVO> results = search(sc, null);
    for (final ImageStoreDetailVO result : results) {
        remove(result.getId());
    }
}
Also used : ImageStoreDetailVO(com.cloud.storage.datastore.db.ImageStoreDetailVO)

Example 4 with ImageStoreDetailVO

use of com.cloud.storage.datastore.db.ImageStoreDetailVO in project cosmic by MissionCriticalCloud.

the class ImageStoreDetailsDaoImpl method update.

@Override
public void update(final long storeId, final Map<String, String> details) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    final SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create();
    sc.setParameters("store", storeId);
    txn.start();
    expunge(sc);
    for (final Map.Entry<String, String> entry : details.entrySet()) {
        final ImageStoreDetailVO detail = new ImageStoreDetailVO(storeId, entry.getKey(), entry.getValue());
        persist(detail);
    }
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ImageStoreDetailVO(com.cloud.storage.datastore.db.ImageStoreDetailVO) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ImageStoreDetailVO (com.cloud.storage.datastore.db.ImageStoreDetailVO)4 HashMap (java.util.HashMap)2 ImageStoreVO (com.cloud.storage.datastore.db.ImageStoreVO)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Map (java.util.Map)1