abh1sar commented on code in PR #12124: URL: https://github.com/apache/cloudstack/pull/12124#discussion_r2663735171
########## plugins/storage/object/ECS/src/main/java/org/apache/cloudstack/storage/datastore/driver/EcsConstants.java: ########## @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cloudstack.storage.datastore.driver; + +public final class EcsConstants { + private EcsConstants() {} Review Comment: Don't think constructor is required here ########## plugins/storage/object/ECS/src/main/java/org/apache/cloudstack/storage/datastore/driver/EcsObjectStoreDriverImpl.java: ########## @@ -137,68 +93,88 @@ public DataStoreTO getStoreTO(final DataStore store) { @Override public Bucket createBucket(final Bucket bucket, final boolean objectLock) { final long storeId = bucket.getObjectStoreId(); - final String name = bucket.getName(); + final String name = bucket.getName(); if (objectLock) { - throw new CloudRuntimeException("Dell ECS doesn't support this feature: object locking"); + throw new InvalidParameterValueException("Dell ECS doesn't support this feature: object locking"); } final Map<String, String> ds = storeDetailsDao.getDetails(storeId); final EcsCfg cfg = ecsCfgFromDetails(ds, storeId); - // Resolve owner username for this bucket final BucketVO vo = bucketDao.findById(bucket.getId()); + if (vo == null) { + throw new CloudRuntimeException("ECS createBucket: bucket record not found: id=" + bucket.getId()); + } + final long accountId = vo.getAccountId(); final Account acct = accountDao.findById(accountId); if (acct == null) { throw new CloudRuntimeException("ECS createBucket: account not found: id=" + accountId); } - final String ownerUser = "cs-" + acct.getUuid(); + + final String ownerUser = getUserPrefix(ds) + acct.getUuid(); // Ensure per-account credentials exist (single-key policy with adopt-if-exists) ensureAccountUserAndSecret(accountId, ownerUser, cfg.mgmtUrl, cfg.saUser, cfg.saPass, cfg.ns, cfg.insecure); - // Quota from UI (INT GB) + // Quota from UI (INT GB). Bucket.getQuota may be Integer; Bucket.getSize may be Long. Integer quotaGb = null; try { - quotaGb = safeIntFromGetter(bucket, "getQuota"); - if (quotaGb == null) quotaGb = safeIntFromGetter(bucket, "getSize"); - } catch (Throwable ignored) { } + quotaGb = bucket.getQuota(); + } catch (Throwable ignored) { + } - final int blockSizeGb = quotaGb != null && quotaGb > 0 ? quotaGb : 2; - final int notifSizeGb = quotaGb != null && quotaGb > 0 ? quotaGb : 1; + if (quotaGb == null) { + try { + final Long sz = bucket.getSize(); + if (sz != null) { + quotaGb = sz.intValue(); + } + } catch (Throwable ignored) { + } + } + + final int blockSizeGb; + final int notifSizeGb; + if (quotaGb != null && quotaGb > 0) { + blockSizeGb = quotaGb; + notifSizeGb = quotaGb; + } else { + blockSizeGb = 2; + notifSizeGb = 1; + } - // Encryption flag from request/VO best-effort - boolean encryptionEnabled = - getBooleanFlagLoose(bucket, "getEncryption", "isEncryption", false) || - getBooleanFlagLoose(bucket, "getEncryptionEnabled", "isEncryptionEnabled", false); + // Encryption flag from request (Bucket has isEncryption()). + boolean encryptionEnabled = bucket.isEncryption(); - if (!encryptionEnabled && vo != null) { - encryptionEnabled = - getBooleanFlagLoose(vo, "getEncryption", "isEncryption", false) || - getBooleanFlagLoose(vo, "getEncryptionEnabled", "isEncryptionEnabled", false); + // Fallback to persisted value if request did not explicitly enable it. + if (!encryptionEnabled) { + try { Review Comment: this try is also not required ########## plugins/storage/object/ECS/src/main/java/org/apache/cloudstack/storage/datastore/driver/EcsObjectStoreDriverImpl.java: ########## @@ -137,68 +93,88 @@ public DataStoreTO getStoreTO(final DataStore store) { @Override public Bucket createBucket(final Bucket bucket, final boolean objectLock) { final long storeId = bucket.getObjectStoreId(); - final String name = bucket.getName(); + final String name = bucket.getName(); if (objectLock) { - throw new CloudRuntimeException("Dell ECS doesn't support this feature: object locking"); + throw new InvalidParameterValueException("Dell ECS doesn't support this feature: object locking"); } final Map<String, String> ds = storeDetailsDao.getDetails(storeId); final EcsCfg cfg = ecsCfgFromDetails(ds, storeId); - // Resolve owner username for this bucket final BucketVO vo = bucketDao.findById(bucket.getId()); + if (vo == null) { + throw new CloudRuntimeException("ECS createBucket: bucket record not found: id=" + bucket.getId()); + } + final long accountId = vo.getAccountId(); final Account acct = accountDao.findById(accountId); if (acct == null) { throw new CloudRuntimeException("ECS createBucket: account not found: id=" + accountId); } - final String ownerUser = "cs-" + acct.getUuid(); + + final String ownerUser = getUserPrefix(ds) + acct.getUuid(); // Ensure per-account credentials exist (single-key policy with adopt-if-exists) ensureAccountUserAndSecret(accountId, ownerUser, cfg.mgmtUrl, cfg.saUser, cfg.saPass, cfg.ns, cfg.insecure); - // Quota from UI (INT GB) + // Quota from UI (INT GB). Bucket.getQuota may be Integer; Bucket.getSize may be Long. Integer quotaGb = null; try { Review Comment: no need for the try block now -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
