From f5d80bbf328ff4d267fd902c193e416f29b49c52 Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Mon, 22 Jun 2020 02:27:01 -0300 Subject: [PATCH 1/5] Update cluster name --- .../java/com/cloud/resource/ResourceService.java | 3 ++- .../command/admin/cluster/UpdateClusterCmd.java | 2 +- .../com/cloud/resource/ResourceManagerImpl.java | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/com/cloud/resource/ResourceService.java b/api/src/main/java/com/cloud/resource/ResourceService.java index 70823084d84c..7f04d8919b97 100644 --- a/api/src/main/java/com/cloud/resource/ResourceService.java +++ b/api/src/main/java/com/cloud/resource/ResourceService.java @@ -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; @@ -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 discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java index 53d01c58a561..381b920e72c0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java @@ -107,7 +107,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()); diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java index c1c221b4f7e2..1484018303df 100755 --- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java @@ -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; @@ -1026,12 +1027,22 @@ 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)) { + cluster.setName(name); + doUpdate = true; + } + if (hypervisor != null && !hypervisor.isEmpty()) { final Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor); if (hypervisorType == null) { From 813ea48c1faf99800936420be3fc2d6ba9f2bc39 Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Mon, 22 Jun 2020 03:22:47 -0300 Subject: [PATCH 2/5] Update name of Host --- .../api/command/admin/host/UpdateHostCmd.java | 7 +++++++ .../cloud/resource/ResourceManagerImpl.java | 21 +++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java index aa0a690e2a98..16fc608930d9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java @@ -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, @@ -73,6 +76,10 @@ public Long getId() { return id; } + public String getName() { + return name; + } + public Long getOsCategoryId() { return osCategoryId; } diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java index 1484018303df..753326ffe0f2 100755 --- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java @@ -1028,12 +1028,12 @@ public void doInTransactionWithoutResult(final TransactionStatus status) { @Override @DB 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) getCluster(cmd.getId()); + final String clusterType = cmd.getClusterType(); + final String hypervisor = cmd.getHypervisor(); + final String allocationState = cmd.getAllocationState(); + final String managedstate = cmd.getManagedstate(); + final String name = cmd.getClusterName(); // Verify cluster information and update the cluster if needed boolean doUpdate = false; @@ -1488,6 +1488,7 @@ public boolean checkAndMaintain(final long hostId) { @Override public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException { final Long hostId = cmd.getId(); + final String name = cmd.getName(); final Long guestOSCategoryId = cmd.getOsCategoryId(); // Verify that the host exists @@ -1505,6 +1506,14 @@ public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException { resourceStateTransitTo(host, resourceEvent, _nodeId); } + if (org.apache.commons.lang.StringUtils.isNotBlank(name)) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Updating Host Name to :" + name); + } + host.setName(name); + _hostDao.persist(host); + } + if (guestOSCategoryId != null) { // Verify that the guest OS Category exists if (!(guestOSCategoryId > 0) || _guestOSCategoryDao.findById(guestOSCategoryId) == null) { From bef567f835c950aa62f4d60cf9060130d043e840 Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Mon, 22 Jun 2020 03:56:47 -0300 Subject: [PATCH 3/5] Fix UpdateClusterCmd for Rolling maintenance, MockResourceManager Update Host name handling to update instead of persist Allow update Storage name --- .../admin/cluster/UpdateClusterCmd.java | 4 ++++ .../admin/storage/UpdateStoragePoolCmd.java | 7 +++++++ .../cloud/resource/ResourceManagerImpl.java | 20 +++++++++---------- .../RollingMaintenanceManagerImpl.java | 8 ++++++-- .../com/cloud/storage/StorageManagerImpl.java | 7 +++++++ .../resource/MockResourceManagerImpl.java | 3 ++- ui/scripts/system.js | 11 ++++++++-- 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java index 381b920e72c0..8d6faf99bdda 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java @@ -63,6 +63,10 @@ public Long getId() { return id; } + public void setId(Long id) { + this.id = id; + } + public String getHypervisor() { return hypervisor; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java index 6bf62282a7ae..ad91c29dde34 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java @@ -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 tags; @@ -66,6 +69,10 @@ public Long getId() { return id; } + public String getName() { + return name; + } + public List getTags() { return tags; } diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java index 753326ffe0f2..8b83cf39ca9e 100755 --- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java @@ -1028,12 +1028,12 @@ public void doInTransactionWithoutResult(final TransactionStatus status) { @Override @DB public Cluster updateCluster(UpdateClusterCmd cmd) { - final ClusterVO cluster = (ClusterVO) getCluster(cmd.getId()); - final String clusterType = cmd.getClusterType(); - final String hypervisor = cmd.getHypervisor(); - final String allocationState = cmd.getAllocationState(); - final String managedstate = cmd.getManagedstate(); - final String name = cmd.getClusterName(); + 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(); // Verify cluster information and update the cluster if needed boolean doUpdate = false; @@ -1487,9 +1487,9 @@ public boolean checkAndMaintain(final long hostId) { @Override public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException { - final Long hostId = cmd.getId(); - final String name = cmd.getName(); - 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); @@ -1511,7 +1511,7 @@ public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException { s_logger.debug("Updating Host Name to :" + name); } host.setName(name); - _hostDao.persist(host); + _hostDao.update(host.getId(), host); } if (guestOSCategoryId != null) { diff --git a/server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java b/server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java index 62bb30e13237..0bc88276fad7 100644 --- a/server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java @@ -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; @@ -114,12 +115,15 @@ public boolean configure(String name, Map params) throws Configu return true; } - private void updateCluster(long clusterId, String state) { + private void updateCluster(long clusterId, String allocationState) { 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, diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java index 79343ab4725f..e8302b621dfb 100644 --- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java @@ -792,6 +792,13 @@ 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)) { + pool.setName(name); + _storagePoolDao.update(pool.getId(), pool); + } + + final List storagePoolTags = cmd.getTags(); if (storagePoolTags != null) { if (s_logger.isDebugEnabled()) { diff --git a/server/src/test/java/com/cloud/resource/MockResourceManagerImpl.java b/server/src/test/java/com/cloud/resource/MockResourceManagerImpl.java index 8ce60df715d6..5fc9a4dcfdb8 100755 --- a/server/src/test/java/com/cloud/resource/MockResourceManagerImpl.java +++ b/server/src/test/java/com/cloud/resource/MockResourceManagerImpl.java @@ -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; @@ -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; } diff --git a/ui/scripts/system.js b/ui/scripts/system.js index 29f428a4f02b..01f8bdc5a2a5 100755 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -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", @@ -17957,7 +17959,8 @@ fields:[ { name: { - label: 'label.name' + label: 'label.name', + isEditable: true } }, { @@ -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", @@ -19684,7 +19690,8 @@ title: 'label.details', fields:[ { name: { - label: 'label.name' + label: 'label.name', + isEditable: true } }, { From 91961eb8f72471c9c8a8d151a9be812bd91ffe0f Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Mon, 22 Jun 2020 17:17:04 -0300 Subject: [PATCH 4/5] add log message for updating cluster and storage pool name --- .../main/java/com/cloud/resource/ResourceManagerImpl.java | 5 ++--- .../src/main/java/com/cloud/storage/StorageManagerImpl.java | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java index 8b83cf39ca9e..29e2639e60ba 100755 --- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java @@ -1039,6 +1039,7 @@ public Cluster updateCluster(UpdateClusterCmd cmd) { boolean doUpdate = false; if (org.apache.commons.lang.StringUtils.isNotBlank(name)) { + s_logger.debug("Updating Cluster name to: " + name); cluster.setName(name); doUpdate = true; } @@ -1507,9 +1508,7 @@ public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException { } if (org.apache.commons.lang.StringUtils.isNotBlank(name)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Updating Host Name to :" + name); - } + s_logger.debug("Updating Host name to: " + name); host.setName(name); _hostDao.update(host.getId(), host); } diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java index e8302b621dfb..4fd883bed289 100644 --- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java @@ -794,6 +794,7 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I 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); } From 9176e290e296ced915e831dc403f5971948aa701 Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Wed, 24 Jun 2020 17:49:56 -0300 Subject: [PATCH 5/5] Prevent renaming VMware cluster as it could cause problems. --- .../src/main/java/com/cloud/resource/ResourceManagerImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java index 29e2639e60ba..52a11069dd0b 100755 --- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java @@ -1039,6 +1039,9 @@ public Cluster updateCluster(UpdateClusterCmd cmd) { boolean doUpdate = false; if (org.apache.commons.lang.StringUtils.isNotBlank(name)) { + if(cluster.getHypervisorType() == HypervisorType.VMware) { + 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;