Skip to content

Commit e0019ec

Browse files
committed
CLOUDSTACK-658 - Adding Scalevm command and XS related changes
1 parent aedb8c4 commit e0019ec

18 files changed

Lines changed: 676 additions & 161 deletions

File tree

api/src/com/cloud/event/EventTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class EventTypes {
5959
public static final String EVENT_VM_REBOOT = "VM.REBOOT";
6060
public static final String EVENT_VM_UPDATE = "VM.UPDATE";
6161
public static final String EVENT_VM_UPGRADE = "VM.UPGRADE";
62+
public static final String EVENT_VM_SCALE = "VM.SCALE";
6263
public static final String EVENT_VM_RESETPASSWORD = "VM.RESETPASSWORD";
6364
public static final String EVENT_VM_RESETSSHKEY = "VM.RESETSSHKEY";
6465
public static final String EVENT_VM_MIGRATE = "VM.MIGRATE";

api/src/com/cloud/vm/UserVmService.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,7 @@
2323

2424
import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
2525
import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
26-
import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd;
27-
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
28-
import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
29-
import org.apache.cloudstack.api.command.user.vm.RebootVMCmd;
30-
import org.apache.cloudstack.api.command.user.vm.RemoveNicFromVMCmd;
31-
import org.apache.cloudstack.api.command.user.vm.ResetVMPasswordCmd;
32-
import org.apache.cloudstack.api.command.user.vm.ResetVMSSHKeyCmd;
33-
import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
34-
import org.apache.cloudstack.api.command.user.vm.StartVMCmd;
35-
import org.apache.cloudstack.api.command.user.vm.UpdateDefaultNicForVMCmd;
36-
import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
37-
import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
26+
import org.apache.cloudstack.api.command.user.vm.*;
3827
import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
3928
import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
4029
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
@@ -401,4 +390,7 @@ UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityExceptio
401390
VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool);
402391

403392
UserVm restoreVM(RestoreVMCmd cmd);
393+
394+
UserVm upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
395+
404396
}

api/src/com/cloud/vm/VirtualMachine.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public enum State {
4141
Destroyed(false, "VM is marked for destroy."),
4242
Expunging(true, "VM is being expunged."),
4343
Migrating(true, "VM is being migrated. host id holds to from host"),
44+
Reconfiguring(true, "VM is being reconfigured to a new service offering"),
4445
Error(false, "VM is in error"),
4546
Unknown(false, "VM state is unknown."),
4647
Shutdowned(false, "VM is shutdowned from inside");
@@ -95,6 +96,9 @@ public static StateMachine2<State, VirtualMachine.Event, VirtualMachine> getStat
9596
s_fsm.addTransition(State.Running, VirtualMachine.Event.StopRequested, State.Stopping);
9697
s_fsm.addTransition(State.Running, VirtualMachine.Event.AgentReportShutdowned, State.Stopped);
9798
s_fsm.addTransition(State.Running, VirtualMachine.Event.AgentReportMigrated, State.Running);
99+
s_fsm.addTransition(State.Running, VirtualMachine.Event.ReconfiguringRequested, State.Reconfiguring);
100+
s_fsm.addTransition(State.Reconfiguring, VirtualMachine.Event.OperationSucceeded, State.Running);
101+
s_fsm.addTransition(State.Reconfiguring, VirtualMachine.Event.OperationFailed, State.Running);
98102
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.MigrationRequested, State.Migrating);
99103
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.OperationSucceeded, State.Running);
100104
s_fsm.addTransition(State.Migrating, VirtualMachine.Event.OperationFailed, State.Running);
@@ -176,7 +180,8 @@ public enum Event {
176180
AgentReportShutdowned,
177181
AgentReportMigrated,
178182
RevertRequested,
179-
SnapshotRequested
183+
SnapshotRequested,
184+
ReconfiguringRequested
180185
};
181186

182187
public enum Type {
@@ -294,4 +299,8 @@ public static boolean isSystemVM(VirtualMachine.Type vmtype) {
294299

295300
public Map<String, String> getDetails();
296301

302+
public Boolean getSameHost();
303+
304+
public Long getNewSvcOfferingId();
305+
297306
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package org.apache.cloudstack.api.command.user.vm;
2+
3+
import com.cloud.exception.*;
4+
import com.cloud.user.Account;
5+
import com.cloud.user.UserContext;
6+
import com.cloud.uservm.UserVm;
7+
import org.apache.cloudstack.api.*;
8+
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
9+
import org.apache.cloudstack.api.response.UserVmResponse;
10+
import org.apache.log4j.Logger;
11+
12+
// Licensed to the Apache Software Foundation (ASF) under one
13+
// or more contributor license agreements. See the NOTICE file
14+
// distributed with this work for additional information
15+
// regarding copyright ownership. The ASF licenses this file
16+
// to you under the Apache License, Version 2.0 (the
17+
// "License"); you may not use this file except in compliance
18+
// with the License. You may obtain a copy of the License at
19+
//
20+
// http://www.apache.org/licenses/LICENSE-2.0
21+
//
22+
// Unless required by applicable law or agreed to in writing,
23+
// software distributed under the License is distributed on an
24+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
25+
// KIND, either express or implied. See the License for the
26+
// specific language governing permissions and limitations
27+
// under the License.
28+
@APICommand(name = "scaleVirtualMachine", description="Scales the virtual machine to a new service offering.", responseObject=UserVmResponse.class)
29+
public class ScaleVMCmd extends BaseCmd {
30+
public static final Logger s_logger = Logger.getLogger(ScaleVMCmd.class.getName());
31+
private static final String s_name = "scalevirtualmachineresponse";
32+
33+
/////////////////////////////////////////////////////
34+
//////////////// API parameters /////////////////////
35+
/////////////////////////////////////////////////////
36+
37+
@ACL
38+
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=UserVmResponse.class,
39+
required=true, description="The ID of the virtual machine")
40+
private Long id;
41+
42+
@ACL
43+
@Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.UUID, entityType=ServiceOfferingResponse.class,
44+
required=true, description="the ID of the service offering for the virtual machine")
45+
private Long serviceOfferingId;
46+
47+
/////////////////////////////////////////////////////
48+
/////////////////// Accessors ///////////////////////
49+
/////////////////////////////////////////////////////
50+
51+
public Long getId() {
52+
return id;
53+
}
54+
55+
public Long getServiceOfferingId() {
56+
return serviceOfferingId;
57+
}
58+
59+
/////////////////////////////////////////////////////
60+
/////////////// API Implementation///////////////////
61+
/////////////////////////////////////////////////////
62+
63+
@Override
64+
public String getCommandName() {
65+
return s_name;
66+
}
67+
68+
public static String getResultObjectName() {
69+
return "virtualmachine";
70+
}
71+
72+
@Override
73+
public long getEntityOwnerId() {
74+
UserVm userVm = _entityMgr.findById(UserVm.class, getId());
75+
if (userVm != null) {
76+
return userVm.getAccountId();
77+
}
78+
79+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
80+
}
81+
82+
@Override
83+
public void execute(){
84+
UserContext.current().setEventDetails("Vm Id: "+getId());
85+
UserVm result = null;
86+
try {
87+
result = _userVmService.upgradeVirtualMachine(this);
88+
} catch (ResourceUnavailableException ex) {
89+
s_logger.warn("Exception: ", ex);
90+
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
91+
} catch (ConcurrentOperationException ex) {
92+
s_logger.warn("Exception: ", ex);
93+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
94+
} catch (ManagementServerException ex) {
95+
s_logger.warn("Exception: ", ex);
96+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
97+
} catch (VirtualMachineMigrationException ex) {
98+
s_logger.warn("Exception: ", ex);
99+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
100+
}
101+
if (result != null){
102+
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
103+
response.setResponseName(getCommandName());
104+
this.setResponseObject(response);
105+
} else {
106+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm");
107+
}
108+
}
109+
}

client/tomcatconf/commands.properties.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ listVirtualMachines=15
6666
getVMPassword=15
6767
restoreVirtualMachine=15
6868
changeServiceForVirtualMachine=15
69+
scaleVirtualMachine=15
6970
assignVirtualMachine=1
7071
migrateVirtualMachine=1
7172
recoverVirtualMachine=7

core/src/com/cloud/vm/VMInstanceVO.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
151151
@Transient
152152
Map<String, String> details;
153153

154+
@Transient
155+
Long newSvcOfferingId;
156+
157+
@Transient
158+
Boolean sameHost;
159+
154160
@Column(name="uuid")
155161
protected String uuid = UUID.randomUUID().toString();
156162
;
@@ -480,4 +486,22 @@ public Long getDiskOfferingId() {
480486
return diskOfferingId;
481487
}
482488

483-
}
489+
@Override
490+
public Long getNewSvcOfferingId() {
491+
return newSvcOfferingId;
492+
}
493+
494+
public void setNewSvcOfferingId(Long oldSvcOfferingId) {
495+
this.newSvcOfferingId = oldSvcOfferingId;
496+
}
497+
498+
@Override
499+
public Boolean getSameHost() {
500+
return sameHost;
501+
}
502+
503+
public void setSameHost(Boolean sameHost) {
504+
this.sameHost = sameHost;
505+
}
506+
507+
}

0 commit comments

Comments
 (0)