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
3 changes: 2 additions & 1 deletion api/src/main/java/com/cloud/resource/ResourceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.UpdateClusterCmd;
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd;
Expand Down Expand Up @@ -58,7 +59,7 @@ public interface ResourceService {

boolean deleteCluster(DeleteClusterCmd cmd);

Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate);
Cluster updateCluster(UpdateClusterCmd cmd);

List<? extends Host> discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getHypervisor() {
return hypervisor;
}
Expand Down Expand Up @@ -107,7 +111,7 @@ public void execute() {
if (cluster == null) {
throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId());
}
Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate());
Cluster result = _resourceService.updateCluster(this);
if (result != null) {
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
clusterResponse.setResponseName(getCommandName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class UpdateHostCmd extends BaseCmd {
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = HostResponse.class, required = true, description = "the ID of the host to update")
private Long id;

@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "Change the name of host", since = "4.15", authorized = {RoleType.Admin})
private String name;

@Parameter(name = ApiConstants.OS_CATEGORY_ID,
type = CommandType.UUID,
entityType = GuestOSCategoryResponse.class,
Expand Down Expand Up @@ -73,6 +76,10 @@ public Long getId() {
return id;
}

public String getName() {
return name;
}

public Long getOsCategoryId() {
return osCategoryId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class UpdateStoragePoolCmd extends BaseCmd {
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = StoragePoolResponse.class, required = true, description = "the Id of the storage pool")
private Long id;

@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, entityType = StoragePoolResponse.class, description = "Change the name of the storage pool", since = "4.15")
private String name;

@Parameter(name = ApiConstants.TAGS, type = CommandType.LIST, collectionType = CommandType.STRING, description = "comma-separated list of tags for the storage pool")
private List<String> tags;

Expand All @@ -66,6 +69,10 @@ public Long getId() {
return id;
}

public String getName() {
return name;
}

public List<String> getTags() {
return tags;
}
Expand Down
30 changes: 26 additions & 4 deletions server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.UpdateClusterCmd;
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd;
Expand Down Expand Up @@ -1026,12 +1027,26 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {

@Override
@DB
public Cluster updateCluster(final Cluster clusterToUpdate, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) {
public Cluster updateCluster(UpdateClusterCmd cmd) {
ClusterVO cluster = (ClusterVO) getCluster(cmd.getId());
String clusterType = cmd.getClusterType();
String hypervisor = cmd.getHypervisor();
String allocationState = cmd.getAllocationState();
String managedstate = cmd.getManagedstate();
String name = cmd.getClusterName();

final ClusterVO cluster = (ClusterVO)clusterToUpdate;
// Verify cluster information and update the cluster if needed
boolean doUpdate = false;

if (org.apache.commons.lang.StringUtils.isNotBlank(name)) {
if(cluster.getHypervisorType() == HypervisorType.VMware) {
Copy link
Member Author

@GabrielBrascher GabrielBrascher Jul 16, 2020

Choose a reason for hiding this comment

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

@rhtyd considering your concerns with issues caused by renaming VMware clusters I added this line.

throw new InvalidParameterValueException("Renaming VMware cluster is not supported as it could cause problems if the updated cluster name is not mapped on VCenter.");
}
s_logger.debug("Updating Cluster name to: " + name);
cluster.setName(name);
doUpdate = true;
}

if (hypervisor != null && !hypervisor.isEmpty()) {
final Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor);
if (hypervisorType == null) {
Expand Down Expand Up @@ -1476,8 +1491,9 @@ public boolean checkAndMaintain(final long hostId) {

@Override
public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
final Long hostId = cmd.getId();
final Long guestOSCategoryId = cmd.getOsCategoryId();
Long hostId = cmd.getId();
String name = cmd.getName();
Long guestOSCategoryId = cmd.getOsCategoryId();

// Verify that the host exists
final HostVO host = _hostDao.findById(hostId);
Expand All @@ -1494,6 +1510,12 @@ public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
resourceStateTransitTo(host, resourceEvent, _nodeId);
}

if (org.apache.commons.lang.StringUtils.isNotBlank(name)) {
s_logger.debug("Updating Host name to: " + name);
host.setName(name);
_hostDao.update(host.getId(), host);
}

if (guestOSCategoryId != null) {
// Verify that the guest OS Category exists
if (!(guestOSCategoryId > 0) || _guestOSCategoryDao.findById(guestOSCategoryId) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.cloud.vm.VirtualMachineProfileImpl;
import com.cloud.vm.dao.VMInstanceDao;
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
import org.apache.cloudstack.api.command.admin.cluster.UpdateClusterCmd;
import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
import org.apache.cloudstack.api.command.admin.resource.StartRollingMaintenanceCmd;
import org.apache.cloudstack.context.CallContext;
Expand Down Expand Up @@ -114,12 +115,15 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
return true;
}

private void updateCluster(long clusterId, String state) {
private void updateCluster(long clusterId, String allocationState) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@nvazquez can you please take a look at it?

I changed API parameter handling from separate parameters on the method call to an object of UpdateClusterCmd class. Therefore, I needed to change this tiny piece of RollingMaintenanceManagerImpl.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @GabrielBrascher, looks good to me. The change needed in RollingMaintenanceManagerImpl will be just the same as you've done below

Cluster cluster = resourceManager.getCluster(clusterId);
if (cluster == null) {
throw new InvalidParameterValueException("Unable to find the cluster by id=" + clusterId);
}
resourceManager.updateCluster(cluster, "", "", state, "");
UpdateClusterCmd updateClusterCmd = new UpdateClusterCmd();
updateClusterCmd.setId(clusterId);
updateClusterCmd.setAllocationState(allocationState);
resourceManager.updateCluster(updateClusterCmd);
}

private void generateReportAndFinishingEvent(StartRollingMaintenanceCmd cmd, boolean success, String details,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,14 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I
throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
}

String name = cmd.getName();
if(org.apache.commons.lang.StringUtils.isNotBlank(name)) {
s_logger.debug("Updating Storage Pool name to: " + name);
pool.setName(name);
_storagePoolDao.update(pool.getId(), pool);
}


final List<String> storagePoolTags = cmd.getTags();
if (storagePoolTags != null) {
if (s_logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.UpdateClusterCmd;
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd;
Expand Down Expand Up @@ -109,7 +110,7 @@ public boolean deleteCluster(final DeleteClusterCmd cmd) {
* @see com.cloud.resource.ResourceService#updateCluster(com.cloud.org.Cluster, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public Cluster updateCluster(final Cluster cluster, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) {
public Cluster updateCluster(UpdateClusterCmd cmd) {
// TODO Auto-generated method stub
return null;
}
Expand Down
11 changes: 9 additions & 2 deletions ui/scripts/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -17023,6 +17023,8 @@
if (args.data.annotation != null && args.data.annotation.length > 0)
array1.push("&annotation=" + args.data.annotation);

if (args.data.name != null && args.data.name.length > 0)
array1.push("&name=" + args.data.name);
$.ajax({
url: createURL("updateHost&id=" + args.context.hosts[0].id + array1.join("")),
dataType: "json",
Expand Down Expand Up @@ -17957,7 +17959,8 @@

fields:[ {
name: {
label: 'label.name'
label: 'label.name',
isEditable: true
}
},
{
Expand Down Expand Up @@ -19552,6 +19555,9 @@
array1.push("&capacityiops=" + capacityIops);
}

if (args.data.name != null && args.data.name.length > 0)
array1.push("&name=" + args.data.name);

$.ajax({
url: createURL("updateStoragePool&id=" + args.context.primarystorages[0].id + array1.join("")),
dataType: "json",
Expand Down Expand Up @@ -19684,7 +19690,8 @@
title: 'label.details',
fields:[ {
name: {
label: 'label.name'
label: 'label.name',
isEditable: true
}
},
{
Expand Down