Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
Expand Down Expand Up @@ -76,6 +77,12 @@ public class ListCfgsByCmd extends BaseListCmd {
description = "the ID of the Account to update the parameter value for corresponding account")
private Long accountId;

@Parameter(name = ApiConstants.IMAGE_STORE_UUID,
type = CommandType.UUID,
entityType = ImageStoreResponse.class,
description = "the ID of the Image Store to update the parameter value for corresponding image store")
private Long imageStoreId;

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
Expand Down Expand Up @@ -104,6 +111,10 @@ public Long getAccountId() {
return accountId;
}

public Long getImageStoreId() {
return imageStoreId;
}

@Override
public Long getPageSizeVal() {
Long defaultPageSize = 500L;
Expand Down Expand Up @@ -147,6 +158,9 @@ public void execute() {
if (getAccountId() != null) {
cfgResponse.setScope("account");
}
if (getImageStoreId() != null){
cfgResponse.setScope("imagestore");
}
configResponses.add(cfgResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.google.common.base.Strings;
import org.apache.cloudstack.acl.RoleService;
import org.apache.log4j.Logger;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiArgValidator;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
Expand All @@ -29,6 +29,7 @@
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;
Expand Down Expand Up @@ -75,6 +76,13 @@ public class UpdateCfgCmd extends BaseCmd {
description = "the ID of the Account to update the parameter value for corresponding account")
private Long accountId;

@Parameter(name = ApiConstants.IMAGE_STORE_UUID,
type = CommandType.UUID,
entityType = ImageStoreResponse.class,
description = "the ID of the Image Store to update the parameter value for corresponding image store",
validations = ApiArgValidator.PositiveNumber)
private Long imageStoreId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -107,6 +115,10 @@ public Long getAccountId() {
return accountId;
}

public Long getImageStoreId() {
return imageStoreId;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
10 changes: 10 additions & 0 deletions engine/components-api/src/com/cloud/capacity/CapacityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public interface CapacityManager {
"If set to true, creates VMs as full clones on ESX hypervisor",
true,
ConfigKey.Scope.StoragePool);
static final ConfigKey<Integer> ImageStoreNFSVersion =
new ConfigKey<Integer>(
Integer.class,
"secstorage.nfs.version",
"Advanced",
null,
"Enforces specific NFS version when mounting Secondary Storage. If NULL default selection is performed",
true,
ConfigKey.Scope.ImageStore,
null);

public boolean releaseVmCapacity(VirtualMachine vm, boolean moveFromReserved, boolean moveToReservered, Long hostId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@
<bean id="hostTagsDaoImpl" class="com.cloud.host.dao.HostTagsDaoImpl" />
<bean id="hostTransferMapDaoImpl" class="com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl" />
<bean id="iPAddressDaoImpl" class="com.cloud.network.dao.IPAddressDaoImpl" />
<bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDaoImpl" />
<bean id="imageStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDetailsDaoImpl" />
<bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl" />
<bean id="imageStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDaoImpl" />
<bean id="imageStoreJoinDaoImpl" class="com.cloud.api.query.dao.ImageStoreJoinDaoImpl" />
<bean id="snapshotDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.SnapshotDataStoreDaoImpl" />
<bean id="templateDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.TemplateDataStoreDaoImpl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.storage.image.db;
package org.apache.cloudstack.storage.datastore.db;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for moving this file to a new location?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @koushik-das, the reason was to avoid a dependency cycle on Maven poms, I tried explaining it under Important section in this PR's description

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that out previously, thanks


import java.util.List;
import java.util.Map;
Expand All @@ -26,8 +26,6 @@
import org.springframework.stereotype.Component;

import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;

import com.cloud.storage.DataStoreRole;
import com.cloud.storage.ScopeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,61 @@
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.cloudstack.api.InternalIdentity;
import org.apache.cloudstack.api.ResourceDetail;

@Entity
@Table(name = "image_store_details")
public class ImageStoreDetailVO implements InternalIdentity {
public class ImageStoreDetailVO implements ResourceDetail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
long id;

@Column(name = "store_id")
long storeId;
long resourceId;

@Column(name = "name")
String name;

@Column(name = "value")
String value;

@Column(name = "display")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the need for this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added it to make it consistent with ResourceDetail as we made ImageStoreDetailVO implement ResourceDetail, which has the method isDisplay.

private boolean display = true;

public ImageStoreDetailVO() {
}

public ImageStoreDetailVO(long storeId, String name, String value) {
this.storeId = storeId;
public ImageStoreDetailVO(long storeId, String name, String value, boolean display) {
this.resourceId = storeId;
this.name = name;
this.value = value;
this.display = display;
}

@Override
public long getId() {
return id;
}

public long getStoreId() {
return storeId;
}

public void setStoreId(long storeId) {
this.storeId = storeId;
@Override
public long getResourceId() {
return resourceId;
}

@Override
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
@Override
public boolean isDisplay() {
return display;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import java.util.Map;

import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;

import com.cloud.utils.db.GenericDao;

public interface ImageStoreDetailsDao extends GenericDao<ImageStoreDetailVO, Long> {
public interface ImageStoreDetailsDao extends GenericDao<ImageStoreDetailVO, Long>, ResourceDetailsDao<ImageStoreDetailVO> {

void update(long storeId, Map<String, String> details);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,36 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.storage.image.db;
package org.apache.cloudstack.storage.datastore.db;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.stereotype.Component;

import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailVO;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;

import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.QueryBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.TransactionLegacy;

import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;

@Component
public class ImageStoreDetailsDaoImpl extends GenericDaoBase<ImageStoreDetailVO, Long> implements ImageStoreDetailsDao {
public class ImageStoreDetailsDaoImpl extends ResourceDetailsDaoBase<ImageStoreDetailVO> implements ImageStoreDetailsDao, ScopedConfigStorage {

protected final SearchBuilder<ImageStoreDetailVO> storeSearch;

protected ImageStoreDetailsDaoImpl() {
public ImageStoreDetailsDaoImpl() {
super();
storeSearch = createSearchBuilder();
storeSearch.and("store", storeSearch.entity().getStoreId(), SearchCriteria.Op.EQ);
storeSearch.and("store", storeSearch.entity().getResourceId(), SearchCriteria.Op.EQ);
storeSearch.done();
}

Expand All @@ -54,7 +56,7 @@ public void update(long storeId, Map<String, String> details) {
txn.start();
expunge(sc);
for (Map.Entry<String, String> entry : details.entrySet()) {
ImageStoreDetailVO detail = new ImageStoreDetailVO(storeId, entry.getKey(), entry.getValue());
ImageStoreDetailVO detail = new ImageStoreDetailVO(storeId, entry.getKey(), entry.getValue(), true);
persist(detail);
}
txn.commit();
Expand Down Expand Up @@ -88,7 +90,30 @@ public void deleteDetails(long storeId) {
for (ImageStoreDetailVO result : results) {
remove(result.getId());
}
}

@Override
public Scope getScope() {
return ConfigKey.Scope.ImageStore;
}

@Override
public ImageStoreDetailVO findDetail(long storeId, String name) {
QueryBuilder<ImageStoreDetailVO> sc = QueryBuilder.create(ImageStoreDetailVO.class);
sc.and(sc.entity().getResourceId(), Op.EQ, storeId);
sc.and(sc.entity().getName(), Op.EQ, name);
return sc.find();
}

@Override
public String getConfigValue(long id, ConfigKey<?> key) {
ImageStoreDetailVO vo = findDetail(id, key.key());
return vo == null ? null : vo.getValue();
}

@Override
public void addDetail(long resourceId, String key, String value, boolean display) {
super.addDetail(new ImageStoreDetailVO(resourceId, key, value, display));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
</property>
</bean>

<bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDaoImpl" />
<bean id="imageStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDetailsDaoImpl" />
<bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl" />
<bean id="imageStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDaoImpl" />
<bean id="snapshotDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.SnapshotDataStoreDaoImpl" />
<bean id="templateDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.TemplateDataStoreDaoImpl" />
<bean id="volumeDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.VolumeDataStoreDaoImpl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
</property>
</bean>

<bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDaoImpl" />
<bean id="imageStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.image.db.ImageStoreDetailsDaoImpl" />
<bean id="imageStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl" />
<bean id="imageStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDaoImpl" />
<bean id="snapshotDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.SnapshotDataStoreDaoImpl" />
<bean id="templateDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.TemplateDataStoreDaoImpl" />
<bean id="volumeDataStoreDaoImpl" class="org.apache.cloudstack.storage.image.db.VolumeDataStoreDaoImpl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@

import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;

import com.cloud.capacity.CapacityManager;

public abstract class NfsImageStoreDriverImpl extends BaseImageStoreDriverImpl {

@Inject
ImageStoreDetailsDao _imageStoreDetailsDao;

private static final String NFS_VERSION_DETAILS_KEY = "nfs.version";

/**
* Retrieve NFS version to be used for imgStoreId store, if provided in image_store_details table
* @param imgStoreId store id
* @return "nfs.version" associated value for imgStoreId in image_store_details table if exists, null if not
* @return "secstorage.nfs.version" associated value for imgStoreId in image_store_details table if exists, null if not
*/
protected Integer getNfsVersion(long imgStoreId){
Map<String, String> imgStoreDetails = _imageStoreDetailsDao.getDetails(imgStoreId);
if (imgStoreDetails != null && imgStoreDetails.containsKey(NFS_VERSION_DETAILS_KEY)){
String nfsVersionParam = imgStoreDetails.get(NFS_VERSION_DETAILS_KEY);
String nfsVersionKey = CapacityManager.ImageStoreNFSVersion.key();
if (imgStoreDetails != null && imgStoreDetails.containsKey(nfsVersionKey)){
String nfsVersionParam = imgStoreDetails.get(nfsVersionKey);
return (nfsVersionParam != null ? Integer.valueOf(nfsVersionParam) : null);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,12 @@ public ImageStoreVO createImageStore(Map<String, Object> params, Map<String, Str
Iterator<String> keyIter = details.keySet().iterator();
while (keyIter.hasNext()) {
String key = keyIter.next().toString();
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) || key.equals(ApiConstants.S3_SECRET_KEY)) {
value = DBEncryptionUtil.encrypt(value);
}
detail.setValue(value);
ImageStoreDetailVO detail = new ImageStoreDetailVO(store.getId(), key, value, true);
imageStoreDetailsDao.persist(detail);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class ConfigKey<T> {

public static enum Scope {
Global, Zone, Cluster, StoragePool, Account, ManagementServer
Global, Zone, Cluster, StoragePool, Account, ManagementServer, ImageStore
}

private final String _category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public ConfigDepotImpl() {
_scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Account, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.ImageStore, new HashSet<ConfigKey<?>>());
}

@Override
Expand Down
Loading