mirror of https://github.com/apache/cloudstack.git
adding support for updating service and disk offerings, also adding domain and domainid back in the responses to the CRUD methods for both service and disk offerings
This commit is contained in:
parent
b51a7fec50
commit
a477d6c33c
|
|
@ -24,6 +24,7 @@ import com.cloud.api.BaseCmd;
|
|||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.response.DiskOfferingResponse;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
|
||||
|
|
@ -48,6 +49,9 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
|
|||
// @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="update tags of the disk offering with this value")
|
||||
// private String tags;
|
||||
|
||||
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings")
|
||||
private Long domainId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -67,6 +71,10 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
|
|||
// public String getTags() {
|
||||
// return tags;
|
||||
// }
|
||||
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import com.cloud.api.BaseCmd;
|
|||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.response.ServiceOfferingResponse;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
|
||||
|
|
@ -53,6 +54,9 @@ public class UpdateServiceOfferingCmd extends BaseCmd {
|
|||
|
||||
@Parameter(name=ApiConstants.USE_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="if true, the VM created from the offering will use default virtual networking. If false, the VM created will use a direct attached networking model. The default value is true.")
|
||||
private Boolean useVirtualNetwork;
|
||||
|
||||
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings")
|
||||
private Long domainId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -82,11 +86,17 @@ public class UpdateServiceOfferingCmd extends BaseCmd {
|
|||
return useVirtualNetwork;
|
||||
}
|
||||
|
||||
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.cloud.api.response;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
|
@ -58,6 +59,9 @@ public class ServiceOfferingResponse extends BaseResponse {
|
|||
|
||||
@SerializedName("domainId") @Param(description="the domain id of the service offering")
|
||||
private Long domainId;
|
||||
|
||||
@SerializedName(ApiConstants.DOMAIN) @Param(description="Domain name for the offering")
|
||||
private String domain;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
|
@ -155,4 +159,14 @@ public class ServiceOfferingResponse extends BaseResponse {
|
|||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -345,7 +345,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
offeringResponse.setOfferHa(offering.getOfferHA());
|
||||
offeringResponse.setUseVirtualNetwork(offering.getGuestIpType().equals(GuestIpType.Virtualized));
|
||||
offeringResponse.setTags(offering.getTags());
|
||||
offeringResponse.setDomainId(offering.getDomainId());
|
||||
if(offering.getDomainId() != null){
|
||||
offeringResponse.setDomain(ApiDBUtils.findDomainById(offering.getDomainId()).getName());
|
||||
offeringResponse.setDomainId(offering.getDomainId());
|
||||
}
|
||||
offeringResponse.setObjectName("serviceoffering");
|
||||
|
||||
return offeringResponse;
|
||||
|
|
|
|||
|
|
@ -1166,7 +1166,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ServiceOffering updateServiceOffering(UpdateServiceOfferingCmd cmd) {
|
||||
String displayText = cmd.getDisplayText();
|
||||
|
|
@ -1176,7 +1176,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
// String tags = cmd.getTags();
|
||||
Boolean useVirtualNetwork = cmd.getUseVirtualNetwork();
|
||||
Long userId = UserContext.current().getUserId();
|
||||
|
||||
Long domainId = cmd.getDomainId();
|
||||
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(User.UID_SYSTEM);
|
||||
}
|
||||
|
|
@ -1186,8 +1187,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
if (offeringHandle == null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find service offering " + id);
|
||||
}
|
||||
|
||||
boolean updateNeeded = (name != null || displayText != null || ha != null || useVirtualNetwork != null);
|
||||
|
||||
boolean updateNeeded = (name != null || displayText != null || ha != null || useVirtualNetwork != null || domainId != null);
|
||||
if (!updateNeeded) {
|
||||
return _serviceOfferingDao.findById(id);
|
||||
}
|
||||
|
|
@ -1211,6 +1212,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
offering.setGuestIpType(guestIpType);
|
||||
}
|
||||
|
||||
if (domainId != null){
|
||||
offering.setDomainId(domainId);
|
||||
}
|
||||
// if (tags != null)
|
||||
// {
|
||||
// if (tags.trim().isEmpty() && offeringHandle.getTags() == null)
|
||||
|
|
@ -1236,7 +1240,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
if (_serviceOfferingDao.update(id, offering)) {
|
||||
offering = _serviceOfferingDao.findById(id);
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully updated service offering with name: " + offering.getName() + ".", "soId=" + offering.getId(), "name=" + offering.getName(),
|
||||
"displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized), "tags=" + offering.getTags());
|
||||
"displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized), "tags=" + offering.getTags(), "domainId=" + offering.getDomainId());
|
||||
return offering;
|
||||
} else {
|
||||
return null;
|
||||
|
|
@ -1287,6 +1291,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
String name = cmd.getDiskOfferingName();
|
||||
String displayText = cmd.getDisplayText();
|
||||
// String tags = cmd.getTags();
|
||||
Long domainId = cmd.getDomainId();
|
||||
|
||||
//Check if diskOffering exists
|
||||
DiskOfferingVO diskOfferingHandle = _diskOfferingDao.findById(diskOfferingId);
|
||||
|
|
@ -1310,6 +1315,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
diskOffering.setDisplayText(displayText);
|
||||
}
|
||||
|
||||
if (domainId != null){
|
||||
diskOffering.setDomainId(domainId);
|
||||
}
|
||||
|
||||
// if (tags != null)
|
||||
// {
|
||||
// if (tags.trim().isEmpty() && diskOfferingHandle.getTags() == null)
|
||||
|
|
@ -1334,7 +1343,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
|
||||
if (_diskOfferingDao.update(diskOfferingId, diskOffering)) {
|
||||
saveConfigurationEvent(UserContext.current().getUserId(), null, EventTypes.EVENT_DISK_OFFERING_EDIT, "Successfully updated disk offering with name: " + diskOffering.getName() + ".", "doId=" + diskOffering.getId(), "name=" + diskOffering.getName(),
|
||||
"displayText=" + diskOffering.getDisplayText(), "diskSize=" + diskOffering.getDiskSize(),"tags=" + diskOffering.getTags());
|
||||
"displayText=" + diskOffering.getDisplayText(), "diskSize=" + diskOffering.getDiskSize(),"tags=" + diskOffering.getTags(),"domainId="+cmd.getDomainId());
|
||||
return _diskOfferingDao.findById(diskOfferingId);
|
||||
} else {
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue