Skip to content

Commit 38e69e5

Browse files
Fix UpdateClusterCmd for Rolling maintenance, MockResourceManager
Update Host name handling to update instead of persist Allow update Storage name
1 parent 813ea48 commit 38e69e5

7 files changed

Lines changed: 48 additions & 15 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public Long getId() {
6363
return id;
6464
}
6565

66+
public void setId(Long id) {
67+
this.id = id;
68+
}
69+
6670
public String getHypervisor() {
6771
return hypervisor;
6872
}

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class UpdateStoragePoolCmd extends BaseCmd {
4545
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = StoragePoolResponse.class, required = true, description = "the Id of the storage pool")
4646
private Long id;
4747

48+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, entityType = StoragePoolResponse.class, description = "Change the name of the storage pool", since = "4.15")
49+
private String name;
50+
4851
@Parameter(name = ApiConstants.TAGS, type = CommandType.LIST, collectionType = CommandType.STRING, description = "comma-separated list of tags for the storage pool")
4952
private List<String> tags;
5053

@@ -66,6 +69,10 @@ public Long getId() {
6669
return id;
6770
}
6871

72+
public String getName() {
73+
return name;
74+
}
75+
6976
public List<String> getTags() {
7077
return tags;
7178
}

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,12 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
10281028
@Override
10291029
@DB
10301030
public Cluster updateCluster(UpdateClusterCmd cmd) {
1031-
final ClusterVO cluster = (ClusterVO) getCluster(cmd.getId());
1032-
final String clusterType = cmd.getClusterType();
1033-
final String hypervisor = cmd.getHypervisor();
1034-
final String allocationState = cmd.getAllocationState();
1035-
final String managedstate = cmd.getManagedstate();
1036-
final String name = cmd.getClusterName();
1031+
ClusterVO cluster = (ClusterVO) getCluster(cmd.getId());
1032+
String clusterType = cmd.getClusterType();
1033+
String hypervisor = cmd.getHypervisor();
1034+
String allocationState = cmd.getAllocationState();
1035+
String managedstate = cmd.getManagedstate();
1036+
String name = cmd.getClusterName();
10371037

10381038
// Verify cluster information and update the cluster if needed
10391039
boolean doUpdate = false;
@@ -1487,9 +1487,9 @@ public boolean checkAndMaintain(final long hostId) {
14871487

14881488
@Override
14891489
public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
1490-
final Long hostId = cmd.getId();
1491-
final String name = cmd.getName();
1492-
final Long guestOSCategoryId = cmd.getOsCategoryId();
1490+
Long hostId = cmd.getId();
1491+
String name = cmd.getName();
1492+
Long guestOSCategoryId = cmd.getOsCategoryId();
14931493

14941494
// Verify that the host exists
14951495
final HostVO host = _hostDao.findById(hostId);
@@ -1511,7 +1511,7 @@ public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
15111511
s_logger.debug("Updating Host Name to :" + name);
15121512
}
15131513
host.setName(name);
1514-
_hostDao.persist(host);
1514+
_hostDao.update(host.getId(), host);
15151515
}
15161516

15171517
if (guestOSCategoryId != null) {

server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.cloud.vm.VirtualMachineProfileImpl;
5050
import com.cloud.vm.dao.VMInstanceDao;
5151
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
52+
import org.apache.cloudstack.api.command.admin.cluster.UpdateClusterCmd;
5253
import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
5354
import org.apache.cloudstack.api.command.admin.resource.StartRollingMaintenanceCmd;
5455
import org.apache.cloudstack.context.CallContext;
@@ -114,12 +115,15 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
114115
return true;
115116
}
116117

117-
private void updateCluster(long clusterId, String state) {
118+
private void updateCluster(long clusterId, String allocationState) {
118119
Cluster cluster = resourceManager.getCluster(clusterId);
119120
if (cluster == null) {
120121
throw new InvalidParameterValueException("Unable to find the cluster by id=" + clusterId);
121122
}
122-
resourceManager.updateCluster(cluster, "", "", state, "");
123+
UpdateClusterCmd updateClusterCmd = new UpdateClusterCmd();
124+
updateClusterCmd.setId(clusterId);
125+
updateClusterCmd.setAllocationState(allocationState);
126+
resourceManager.updateCluster(updateClusterCmd);
123127
}
124128

125129
private void generateReportAndFinishingEvent(StartRollingMaintenanceCmd cmd, boolean success, String details,

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,13 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I
792792
throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
793793
}
794794

795+
String name = cmd.getName();
796+
if(org.apache.commons.lang.StringUtils.isNotBlank(name)) {
797+
pool.setName(name);
798+
_storagePoolDao.update(pool.getId(), pool);
799+
}
800+
801+
795802
final List<String> storagePoolTags = cmd.getTags();
796803
if (storagePoolTags != null) {
797804
if (s_logger.isDebugEnabled()) {

server/src/test/java/com/cloud/resource/MockResourceManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
2727
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
28+
import org.apache.cloudstack.api.command.admin.cluster.UpdateClusterCmd;
2829
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
2930
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
3031
import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd;
@@ -109,7 +110,7 @@ public boolean deleteCluster(final DeleteClusterCmd cmd) {
109110
* @see com.cloud.resource.ResourceService#updateCluster(com.cloud.org.Cluster, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
110111
*/
111112
@Override
112-
public Cluster updateCluster(final Cluster cluster, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) {
113+
public Cluster updateCluster(UpdateClusterCmd cmd) {
113114
// TODO Auto-generated method stub
114115
return null;
115116
}

ui/scripts/system.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15473,6 +15473,9 @@
1547315473
action: function (args) {
1547415474
var array1 =[];
1547515475

15476+
if (args.data.name != null && args.data.name.length > 0)
15477+
array1.push("&name=" + args.data.name);
15478+
1547615479
$.ajax({
1547715480
url: createURL("updateCluster&id=" + args.context.clusters[0].id + array1.join("")),
1547815481
dataType: "json",
@@ -17023,6 +17026,8 @@
1702317026
if (args.data.annotation != null && args.data.annotation.length > 0)
1702417027
array1.push("&annotation=" + args.data.annotation);
1702517028

17029+
if (args.data.name != null && args.data.name.length > 0)
17030+
array1.push("&name=" + args.data.name);
1702617031
$.ajax({
1702717032
url: createURL("updateHost&id=" + args.context.hosts[0].id + array1.join("")),
1702817033
dataType: "json",
@@ -17957,7 +17962,8 @@
1795717962

1795817963
fields:[ {
1795917964
name: {
17960-
label: 'label.name'
17965+
label: 'label.name',
17966+
isEditable: true
1796117967
}
1796217968
},
1796317969
{
@@ -19552,6 +19558,9 @@
1955219558
array1.push("&capacityiops=" + capacityIops);
1955319559
}
1955419560

19561+
if (args.data.name != null && args.data.name.length > 0)
19562+
array1.push("&name=" + args.data.name);
19563+
1955519564
$.ajax({
1955619565
url: createURL("updateStoragePool&id=" + args.context.primarystorages[0].id + array1.join("")),
1955719566
dataType: "json",
@@ -19684,7 +19693,8 @@
1968419693
title: 'label.details',
1968519694
fields:[ {
1968619695
name: {
19687-
label: 'label.name'
19696+
label: 'label.name',
19697+
isEditable: true
1968819698
}
1968919699
},
1969019700
{

0 commit comments

Comments
 (0)