Skip to content

Commit e0de79b

Browse files
author
Alena Prokharchyk
committed
Resource metadata: by default, all metadata is set with display=true (meaning that the detail is avaialble for display to the regular user). If admin wants to set a specific detail to be false, he has to specify it explicitly in addResourceDetail command
1 parent 13bf1ec commit e0de79b

72 files changed

Lines changed: 227 additions & 123 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/server/ResourceMetaDataService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public interface ResourceMetaDataService {
3030
* @param resourceId TODO
3131
* @param resourceType
3232
* @param details
33+
* @param forDisplay TODO
3334
* @return
3435
*/
35-
boolean addResourceMetaData(String resourceId, ResourceObjectType resourceType, Map<String, String> details);
36+
boolean addResourceMetaData(String resourceId, ResourceObjectType resourceType, Map<String, String> details, boolean forDisplay);
3637

3738
/**
3839
*

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ public class ApiConstants {
549549
public static final String PASSIVE = "passive";
550550
public static final String VERSION = "version";
551551
public static final String START = "start";
552+
public static final String DISPLAY = "display";
552553

553554
public enum HostDetails {
554555
all, capacity, events, stats, min;

api/src/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class AddResourceDetailCmd extends BaseAsyncCmd {
4949
@Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, required = true, collectionType = CommandType.STRING, description = "resource id to create the details for")
5050
private String resourceId;
5151

52+
@Parameter(name = ApiConstants.DISPLAY, type = CommandType.BOOLEAN, description = "pass false if you want this detail to be disabled for the regular user. True by default")
53+
private Boolean display;
54+
5255
/////////////////////////////////////////////////////
5356
/////////////////// Accessors ///////////////////////
5457
/////////////////////////////////////////////////////
@@ -77,6 +80,14 @@ public String getResourceId() {
7780
return resourceId;
7881
}
7982

83+
public boolean forDisplay() {
84+
if (display != null) {
85+
return display;
86+
} else {
87+
return true;
88+
}
89+
}
90+
8091
/////////////////////////////////////////////////////
8192
/////////////// API Implementation///////////////////
8293
/////////////////////////////////////////////////////
@@ -104,7 +115,7 @@ public String getEventDescription() {
104115

105116
@Override
106117
public void execute() {
107-
_resourceMetaDataService.addResourceMetaData(getResourceId(), getResourceType(), getDetails());
118+
_resourceMetaDataService.addResourceMetaData(getResourceId(), getResourceType(), getDetails(), forDisplay());
108119
setResponseObject(new SuccessResponse(getCommandName()));
109120
}
110121
}

api/src/org/apache/cloudstack/api/command/user/volume/ListResourceDetailsCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ListResourceDetailsCmd extends BaseListProjectAndAccountResourcesCm
3737
@Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, description = "list by resource type", required = true)
3838
private String resourceType;
3939

40-
@Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, description = "list by resource id", required = true)
40+
@Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, description = "list by resource id")
4141
private String resourceId;
4242

4343
@Parameter(name = ApiConstants.KEY, type = CommandType.STRING, description = "list by key")

api/src/org/apache/cloudstack/api/response/VolumeResponse.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public class VolumeResponse extends BaseResponse implements ControlledViewEntity
190190

191191
@SerializedName(ApiConstants.DISPLAY_VOLUME)
192192
@Param(description = "an optional field whether to the display the volume to the end user or not.")
193-
private Boolean displayVm;
193+
private Boolean displayVolume;
194194

195195
@SerializedName(ApiConstants.PATH)
196196
@Param(description = "The path of the volume")
@@ -406,12 +406,12 @@ public void addTag(ResourceTagResponse tag) {
406406
this.tags.add(tag);
407407
}
408408

409-
public Boolean getDisplayVm() {
410-
return displayVm;
409+
public Boolean getDisplayVolume() {
410+
return displayVolume;
411411
}
412412

413-
public void setDisplayVm(Boolean displayVm) {
414-
this.displayVm = displayVm;
413+
public void setDisplayVolume(Boolean displayVm) {
414+
this.displayVolume = displayVm;
415415
}
416416

417417
public void setStoragePoolId(String storagePoolId) {

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import javax.inject.Inject;
4141
import javax.naming.ConfigurationException;
4242

43-
import org.apache.log4j.Logger;
44-
4543
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
4644
import org.apache.cloudstack.context.CallContext;
4745
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@@ -69,6 +67,7 @@
6967
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
7068
import org.apache.cloudstack.storage.to.VolumeObjectTO;
7169
import org.apache.cloudstack.utils.identity.ManagementServerNode;
70+
import org.apache.log4j.Logger;
7271

7372
import com.cloud.agent.AgentManager;
7473
import com.cloud.agent.Listener;
@@ -939,11 +938,11 @@ public void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Obj
939938
//storing the value of overcommit in the vm_details table for doing a capacity check in case the cluster overcommit ratio is changed.
940939
if (_uservmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio") == null &&
941940
((Float.parseFloat(cluster_detail_cpu.getValue()) > 1f || Float.parseFloat(cluster_detail_ram.getValue()) > 1f))) {
942-
_uservmDetailsDao.addDetail(vm.getId(), "cpuOvercommitRatio", cluster_detail_cpu.getValue());
943-
_uservmDetailsDao.addDetail(vm.getId(), "memoryOvercommitRatio", cluster_detail_ram.getValue());
941+
_uservmDetailsDao.addDetail(vm.getId(), "cpuOvercommitRatio", cluster_detail_cpu.getValue(), true);
942+
_uservmDetailsDao.addDetail(vm.getId(), "memoryOvercommitRatio", cluster_detail_ram.getValue(), true);
944943
} else if (_uservmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio") != null) {
945-
_uservmDetailsDao.addDetail(vm.getId(), "cpuOvercommitRatio", cluster_detail_cpu.getValue());
946-
_uservmDetailsDao.addDetail(vm.getId(), "memoryOvercommitRatio", cluster_detail_ram.getValue());
944+
_uservmDetailsDao.addDetail(vm.getId(), "cpuOvercommitRatio", cluster_detail_cpu.getValue(), true);
945+
_uservmDetailsDao.addDetail(vm.getId(), "memoryOvercommitRatio", cluster_detail_ram.getValue(), true);
947946
}
948947
vmProfile.setCpuOvercommitRatio(Float.parseFloat(cluster_detail_cpu.getValue()));
949948
vmProfile.setMemoryOvercommitRatio(Float.parseFloat(cluster_detail_ram.getValue()));

engine/schema/src/com/cloud/dc/DataCenterDetailVO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public class DataCenterDetailVO implements ResourceDetail {
4848
protected DataCenterDetailVO() {
4949
}
5050

51-
public DataCenterDetailVO(long dcId, String name, String value) {
51+
public DataCenterDetailVO(long dcId, String name, String value, boolean display) {
5252
this.resourceId = dcId;
5353
this.name = name;
5454
this.value = value;
55+
this.display = display;
5556
}
5657

5758
@Override

engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public void saveDetails(DataCenterVO zone) {
375375

376376
List<DataCenterDetailVO> resourceDetails = new ArrayList<DataCenterDetailVO>();
377377
for (String key : details.keySet()) {
378-
resourceDetails.add(new DataCenterDetailVO(zone.getId(), key, details.get(key)));
378+
resourceDetails.add(new DataCenterDetailVO(zone.getId(), key, details.get(key), true));
379379
}
380380

381381
_detailsDao.saveDetails(resourceDetails);

engine/schema/src/com/cloud/dc/dao/DataCenterDetailsDaoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public String getConfigValue(long id, ConfigKey<?> key) {
4141
}
4242

4343
@Override
44-
public void addDetail(long resourceId, String key, String value) {
45-
super.addDetail(new DataCenterDetailVO(resourceId, key, value));
44+
public void addDetail(long resourceId, String key, String value, boolean display) {
45+
super.addDetail(new DataCenterDetailVO(resourceId, key, value, display));
4646
}
4747

4848
}

engine/schema/src/com/cloud/network/dao/NetworkDetailVO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public class NetworkDetailVO implements ResourceDetail {
4848
public NetworkDetailVO() {
4949
}
5050

51-
public NetworkDetailVO(long networkId, String name, String value) {
51+
public NetworkDetailVO(long networkId, String name, String value, boolean display) {
5252
this.resourceId = networkId;
5353
this.name = name;
5454
this.value = value;
55+
this.display = display;
5556
}
5657

5758
@Override

0 commit comments

Comments
 (0)