Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
d3b8e74
API command initialization
cron-ns Jun 7, 2021
e2f7228
first step to create the clone api execution
cron-ns Jun 10, 2021
6a2237c
Merge branch 'main' of https://github.com/atrocitytheme/cloudstack in…
cron-ns Jun 16, 2021
6b2604d
add findISO and findVO steps
cron-ns Jun 18, 2021
8c815ab
add creation of root-disk -> template -> vm step
cron-ns Jun 21, 2021
fb6cb0a
prepare the template impl
cron-ns Jun 23, 2021
77c39c2
clear the dot record for later test
cron-ns Jun 23, 2021
1971a39
checks for VM are implemented
cron-ns Jun 25, 2021
3687110
fix checkstyle
cron-ns Jun 25, 2021
fbb886c
compilation fixed
cron-ns Jun 25, 2021
16d75da
checkClone debug
cron-ns Jun 25, 2021
779681c
server state update
cron-ns Jun 25, 2021
5a81d2b
add and statement
cron-ns Jun 25, 2021
6f4fca9
fix null error
cron-ns Jun 25, 2021
896b033
test hit the current vm information
cron-ns Jun 28, 2021
cfd131c
fix typo of star import
cron-ns Jun 28, 2021
9677858
fix the null pt except
cron-ns Jun 28, 2021
85129ee
add vm record creation code
cron-ns Jun 28, 2021
b6607f4
add the user vm db creation code
cron-ns Jun 28, 2021
afae560
add vm creation typo fix
cron-ns Jun 28, 2021
0a1405d
change ip to available
cron-ns Jun 28, 2021
64c0fd5
fix ip issue
cron-ns Jun 28, 2021
e04dc22
fix the vm creation detail
cron-ns Jun 28, 2021
7bef87f
template zone addition code
cron-ns Jul 2, 2021
d15f620
trail-issue-1
cron-ns Jul 2, 2021
fee4a95
change test ip address
cron-ns Jul 2, 2021
eecacc0
add template download record
cron-ns Jul 2, 2021
31824f2
get the template created and prepare for the vm start
cron-ns Jul 4, 2021
e3bf894
fix unknown symbol
cron-ns Jul 4, 2021
99e5043
finish the final private creation
cron-ns Jul 4, 2021
40abfac
add logger information
cron-ns Jul 4, 2021
d235477
add autobox statement
cron-ns Jul 4, 2021
a48d7fa
add template Id setting
cron-ns Jul 5, 2021
7fb0994
use uuid as replacement of template
cron-ns Jul 5, 2021
ed9ac4e
fix the template recording bug
cron-ns Jul 5, 2021
23a53cb
fix instance creation null
cron-ns Jul 5, 2021
53785ed
fix the template creation sequence
cron-ns Jul 5, 2021
306a7f4
finish the start vm coding
cron-ns Jul 5, 2021
8ecb6a5
fix start virtual machine null pointer bug
cron-ns Jul 5, 2021
a1bf574
add public ip address for kvm host test
cron-ns Jul 5, 2021
9639389
new clone ip added
cron-ns Jul 5, 2021
0871f74
change test ip to 98
cron-ns Jul 5, 2021
f5b896e
fixing the first password issue
cron-ns Jul 7, 2021
8bebd3b
fix the style code
cron-ns Jul 7, 2021
21ac7a7
audit the star
cron-ns Jul 7, 2021
385df67
location type changed
cron-ns Jul 7, 2021
cec1ee9
fix the snapshot policy
cron-ns Jul 7, 2021
d4d7570
add automatic ip assignment-
cron-ns Jul 8, 2021
52f2810
add ip allocation
cron-ns Jul 8, 2021
1a475b3
fix the check-style typo
cron-ns Jul 8, 2021
b64c48b
try null address for vm creation
cron-ns Jul 8, 2021
6b145d1
ignore unused ip
cron-ns Jul 8, 2021
fbf3753
finish the network allocation
cron-ns Jul 8, 2021
63c7c5e
datadisk code added
cron-ns Jul 9, 2021
fcb8152
fix the import typos
cron-ns Jul 9, 2021
78d5295
fix the service api impl
cron-ns Jul 11, 2021
1414e3a
clear unused import
cron-ns Jul 11, 2021
8771728
ake the data disk shown
cron-ns Jul 11, 2021
c6279ce
data disk snapshot clearance and exception handler
cron-ns Jul 12, 2021
8fd5eb5
resolve main branch conflict
cron-ns Jul 14, 2021
579fe8a
Merge pull request #1 from atrocitytheme/test
atrocitytheme Jul 15, 2021
a005f1c
Merge branch 'apache:main' into main
atrocitytheme Jul 15, 2021
d339b54
Merge pull request #3 from atrocitytheme/main
atrocitytheme Jul 15, 2021
0415cbc
error handling complates
cron-ns Jul 16, 2021
4542f6b
Merge pull request #5 from atrocitytheme/test
atrocitytheme Jul 16, 2021
03e380f
modify usage manager
cron-ns Jul 19, 2021
4d6d6cf
change the usage server
cron-ns Jul 19, 2021
678d9d8
debug logger enabled
cron-ns Jul 19, 2021
8ea6949
fix the usage event snapshot event recording
cron-ns Jul 20, 2021
794ca8f
Merge pull request #6 from atrocitytheme/test
atrocitytheme Jul 20, 2021
d9eac6e
add front end for clone virtuial machine
cron-ns Jul 25, 2021
14fa30c
fix lint
cron-ns Jul 25, 2021
0d893f0
modify show condition
cron-ns Jul 25, 2021
c72654c
change ui icon
cron-ns Jul 25, 2021
b0ab18b
ping first test case
cron-ns Jul 28, 2021
a423887
fix checkstyle
cron-ns Jul 28, 2021
4a3fc6d
fix null mackito
cron-ns Jul 28, 2021
83a25c8
Merge pull request #7 from atrocitytheme/test
atrocitytheme Jul 28, 2021
d925bed
add integration test for clone
cron-ns Aug 6, 2021
cdbbd60
add clone tag to test
cron-ns Aug 6, 2021
6af4d28
fix the virtualmachine id attribute
cron-ns Aug 6, 2021
a743d20
fix the integration target
cron-ns Aug 7, 2021
1194b63
debug msg and vm id logged
cron-ns Aug 8, 2021
0521448
fix the size integration test
cron-ns Aug 8, 2021
de15e9d
fix the resource limit check
cron-ns Aug 8, 2021
76f9869
fix min root size
cron-ns Aug 8, 2021
dee4406
fix size error when the template is not healthy
cron-ns Aug 8, 2021
b1ad52c
fix the permission issue
cron-ns Aug 8, 2021
9401571
finish the assertion of clone vm integration test
cron-ns Aug 8, 2021
0cafec9
migrate clone vm to seperate class cycle test
cron-ns Aug 8, 2021
43d00b3
fix typo
cron-ns Aug 8, 2021
fa552ce
Test (#8)
atrocitytheme Aug 9, 2021
13bb0a5
refactor the clone to service layer
cron-ns Aug 13, 2021
8b55262
fix checkstyle
cron-ns Aug 13, 2021
56f4d1c
server style fix:
cron-ns Aug 13, 2021
4efd6b6
fix custom id option
cron-ns Aug 13, 2021
d65ab7b
Merge pull request #9 from atrocitytheme/test
atrocitytheme Aug 13, 2021
aa02972
fix virtualmachine id variable naming
cron-ns Aug 13, 2021
a669bf0
Merge pull request #10 from atrocitytheme/test
atrocitytheme Aug 13, 2021
9f58ebd
resolve conflit
cron-ns Aug 16, 2021
53cbda0
resolve main branch conflict
cron-ns Aug 16, 2021
feb0325
Merge branch 'test' of github.com:atrocitytheme/cloudstack into test
cron-ns Aug 16, 2021
5fa517e
fix remaining bugs and refactor
cron-ns Aug 17, 2021
ab56212
Merge pull request #13 from atrocitytheme/test
atrocitytheme Aug 17, 2021
8abf141
remove getter and setter of cloneVmCmd
cron-ns Aug 18, 2021
50d250e
fix checkstyle:trailingspace
cron-ns Aug 18, 2021
1f6ae9b
Refactor CloneCmd and remove getter and setter
atrocitytheme Aug 18, 2021
ee6ce66
change execute sequence and apply new tests
cron-ns Aug 18, 2021
9ffd335
fix null name
cron-ns Aug 18, 2021
862f901
fix ui
cron-ns Aug 18, 2021
28e417c
typo check
cron-ns Aug 18, 2021
4e7f40f
fix null pointer
cron-ns Aug 18, 2021
a44bba9
add new test
cron-ns Aug 18, 2021
826ea4d
finish the test
cron-ns Aug 18, 2021
2ab2472
update the smoke test to ignore specific vm
cron-ns Aug 19, 2021
c3e836a
fix restore vm
cron-ns Aug 19, 2021
59bc42a
Upgrade smoke test of kvm.enabled.snapshot and refactor the implement…
atrocitytheme Aug 19, 2021
2fd4ca0
fix typo and delete trivial comments
cron-ns Aug 22, 2021
a470cea
fix typo and delete trivial comments
atrocitytheme Aug 22, 2021
6ff0ce4
optimize test implementation
cron-ns Aug 22, 2021
a0314bf
optimize test implementation
atrocitytheme Aug 22, 2021
520e951
add clean up resources
cron-ns Aug 22, 2021
cec42c3
add clean up resources
atrocitytheme Aug 22, 2021
5072889
fix the orchestrator
cron-ns Aug 24, 2021
a1e22b7
add None checker if kvm enabled var doesn't exist
cron-ns Aug 24, 2021
ae25c4a
add cleanup code
cron-ns Aug 24, 2021
866a21d
Merge pull request #20 from atrocitytheme/test
atrocitytheme Sep 5, 2021
6b6cffb
Merge branch 'main' into full-clone
sureshanaparti Nov 8, 2021
b89f788
Fixed issues with merge conflicts
sureshanaparti Nov 8, 2021
379309e
resolve project conflict
atrocitytheme Mar 5, 2022
1f41407
Merge branch 'apache-main' into full-clone
atrocitytheme Mar 5, 2022
7b048c4
resolve the compatability issue
atrocitytheme Mar 5, 2022
40788cf
resolve the checkstyle imports
atrocitytheme Mar 5, 2022
8da90f7
Implementation for compatability
atrocitytheme Mar 5, 2022
04a6f05
fix checkstyle
atrocitytheme Mar 5, 2022
fb99861
fix snapshot method compatability
atrocitytheme Mar 5, 2022
63d3da1
fix legacy snapshot methods
atrocitytheme Mar 5, 2022
feb548b
Merge branch 'main' into full-clone
sureshanaparti Jul 28, 2022
733b903
Merge branch 'main' into full-clone
DaanHoogland Jan 9, 2023
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
1 change: 1 addition & 0 deletions api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public class EventTypes {
public static final String EVENT_VM_IMPORT = "VM.IMPORT";
public static final String EVENT_VM_UNMANAGE = "VM.UNMANAGE";
public static final String EVENT_VM_RECOVER = "VM.RECOVER";
public static final String EVENT_VM_CLONE = "VM.CLONE";

// Domain Router
public static final String EVENT_ROUTER_CREATE = "ROUTER.CREATE";
Expand Down
4 changes: 4 additions & 0 deletions api/src/main/java/com/cloud/network/NetworkModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public interface NetworkModel {

List<? extends Network> listNetworksUsedByVm(long vmId, boolean isSystem);

default List<Long> listNetworksUsedByVm(long vmId) {
throw new UnsupportedOperationException();
}

Nic getNicInNetwork(long vmId, long networkId);

List<? extends Nic> getNicsForTraffic(long vmId, TrafficType type);
Expand Down
4 changes: 3 additions & 1 deletion api/src/main/java/com/cloud/storage/Snapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

public interface Snapshot extends ControlledEntity, Identity, InternalIdentity, StateObject<Snapshot.State> {
public enum Type {
MANUAL, RECURRING, TEMPLATE, HOURLY, DAILY, WEEKLY, MONTHLY, GROUP;
MANUAL, RECURRING, TEMPLATE, HOURLY, DAILY, WEEKLY, MONTHLY, GROUP, INTERNAL;
// New types should be defined after INTERNAL, and change the max value
private int max = 8;

public void setMax(int max) {
Expand Down Expand Up @@ -71,6 +72,7 @@ enum LocationType {
}

public static final long MANUAL_POLICY_ID = 0L;
public static final long INTERNAL_POLICY_ID = 8L;

@Override
long getAccountId();
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/com/cloud/storage/VolumeApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.net.MalformedURLException;
import java.util.Map;

import com.cloud.exception.StorageUnavailableException;
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.ChangeOfferingForVolumeCmd;
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
Expand Down Expand Up @@ -101,6 +102,8 @@ public interface VolumeApiService {

Volume detachVolumeViaDestroyVM(long vmId, long volumeId);

Volume cloneDataVolume(long vmId, long snapshotId, Volume volume) throws StorageUnavailableException;

Volume detachVolumeFromVM(DetachVolumeCmd cmd);

Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm, Snapshot.LocationType locationType, boolean asyncBackup, Map<String, String> tags)
Expand All @@ -110,6 +113,8 @@ Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account acc

Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long owner, String chainInfo, String name);

Volume attachVolumeToVM(Long vmId, Long volumeId, Long deviceId);

/**
* Extracts the volume to a particular location.
*
Expand Down
13 changes: 13 additions & 0 deletions api/src/main/java/com/cloud/template/TemplateApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.net.URISyntaxException;
import java.util.List;

import com.cloud.storage.Snapshot;
import com.cloud.storage.VolumeApiService;
import com.cloud.uservm.UserVm;
import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd;
import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd;
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
Expand All @@ -40,6 +43,7 @@
import com.cloud.exception.StorageUnavailableException;
import com.cloud.user.Account;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.api.command.user.vm.CloneVMCmd;
import org.apache.cloudstack.api.command.user.userdata.LinkUserDataToTemplateCmd;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;

Expand Down Expand Up @@ -102,6 +106,15 @@ public interface TemplateApiService {

boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissionsCmd cmd);

Snapshot createSnapshotFromTemplateOwner(long vmId, UserVm curVm, Account templateOwner, VolumeApiService volumeService) throws ResourceAllocationException;

/**
* create a template record for later usage of creating a real template by createPrivateTemplate
* */
VirtualMachineTemplate createPrivateTemplateRecord(CloneVMCmd cmd, Account templateOwner, VolumeApiService serviceObj, Snapshot snapshot) throws ResourceAllocationException;

VirtualMachineTemplate createPrivateTemplate(CloneVMCmd cmd, long snapshotId, long templateId) throws CloudRuntimeException;

VirtualMachineTemplate createPrivateTemplateRecord(CreateTemplateCmd cmd, Account templateOwner) throws ResourceAllocationException;

VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd command) throws CloudRuntimeException;
Expand Down
19 changes: 19 additions & 0 deletions api/src/main/java/com/cloud/vm/UserVmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;

import com.cloud.storage.VolumeApiService;
import com.cloud.storage.snapshot.SnapshotApiService;
import org.apache.cloudstack.api.BaseCmd.HTTPMethod;
import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd;
import org.apache.cloudstack.api.command.user.vm.CloneVMCmd;
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
import org.apache.cloudstack.api.command.user.vm.RebootVMCmd;
Expand Down Expand Up @@ -86,6 +90,18 @@ public interface UserVmService {
*/
UserVm destroyVm(long vmId, boolean expunge) throws ResourceUnavailableException, ConcurrentOperationException;

/**
* Clone a specific VM (full clone)
*
* @param cmd
* - the command specifying vmId to be cloned
* @return the VM if cloneVM operation is successful
* */
Optional<UserVm> cloneVirtualMachine(CloneVMCmd cmd, VolumeApiService volumeService, SnapshotApiService snapshotService) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException;

void validateCloneCondition(CloneVMCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException, ResourceAllocationException;

void prepareCloneVirtualMachine(CloneVMCmd cmd) throws ResourceAllocationException, InsufficientCapacityException, ResourceUnavailableException;
/**
* Resets the password of a virtual machine.
*
Expand Down Expand Up @@ -432,6 +448,9 @@ UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffe
UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException,
StorageUnavailableException, ResourceAllocationException;

UserVm recordVirtualMachineToDB(CloneVMCmd cmd, long templateId) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException,
StorageUnavailableException, ResourceAllocationException;

UserVm getUserVm(long vmId);

VirtualMachine getVm(long vmId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public String getCreateEventType() {
public String getCreateEventDescription() {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.user.vm;

import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.ACL;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ResponseObject;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.user.UserCmd;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;

import java.util.Optional;

@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a virtual VM",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a virtual VM",
@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a virtual machine",

or

Suggested change
@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a virtual VM",
@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a VM",

responseView = ResponseObject.ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true, entityType = {VirtualMachine.class}, since="4.16.0")
public class CloneVMCmd extends BaseAsyncCreateCmd implements UserCmd {
public static final Logger s_logger = Logger.getLogger(CloneVMCmd.class.getName());
private static final String s_name = "clonevirtualmachineresponse";
private static final String CLONE_IDENTIFIER = "Clone";

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@ACL(accessType = AccessType.OperateEntry)
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, entityType=UserVmResponse.class,
required = true, description = "The ID of the virtual machine")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
required = true, description = "The ID of the virtual machine")
required = true, description = "The ID of the virtual machine to clone")

Copy link
Contributor

@DaanHoogland DaanHoogland Aug 20, 2021

Choose a reason for hiding this comment

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

@atrocitytheme can you add a reason why you didn't apply this suggestion?

private Long virtualmachineid;

@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "name of the cloned virtual machine")
private String name;

//Owner information
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an optional account for the virtual machine. Must be used with domainId.")
private String accountName;

@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "an optional domainId for the virtual machine. If the account parameter is used, domainId must also be used.")
private Long domainId;

public String getAccountName() {
return accountName;
}

public Long getDomainId() {
return domainId;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public Long getId() {
return this.virtualmachineid;
}
@Override
public String getEventType() {
return EventTypes.EVENT_VM_CLONE;
}

@Override
public ApiCommandJobType getInstanceType() {
return ApiCommandJobType.VirtualMachine;
}

@Override
public String getEventDescription() {
return "Cloning user VM: " + this._uuidMgr.getUuid(VirtualMachine.class, getId());
}

@Override
public void create() throws ResourceAllocationException {
try {
_userVmService.validateCloneCondition(this);
_userVmService.prepareCloneVirtualMachine(this);
}
catch (ResourceUnavailableException | InsufficientCapacityException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, e.getMessage());
} catch (InvalidParameterValueException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (ServerApiException e) {
throw new ServerApiException(e.getErrorCode(), e.getDescription());
} catch (CloudRuntimeException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
Comment on lines +113 to +122
Copy link
Contributor

Choose a reason for hiding this comment

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

We could improve these logs with some context data and unify the catches.

}
}

public boolean isPublic() {
return false;
}

public String getVMName() {
if (getName() == null) {
return getTargetVM().getInstanceName() + "-" + CLONE_IDENTIFIER;
}
return getName();
}

public String getTemplateName() {
return (getVMName() + "-" + _uuidMgr.generateUuid(VirtualMachineTemplate.class, null)).substring(0, 32);
}

@Override
public void execute() {
Optional<UserVm> result;
try {
CallContext.current().setEventDetails("Vm Id for full clone: " + getEntityId());
s_logger.info("starting actual VM id: " + getEntityId());
result = _userVmService.cloneVirtualMachine(this, _volumeService, _snapshotService);
Copy link
Contributor

Choose a reason for hiding this comment

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

check if volume and snapshot service objects are required to be passed here, or these can be accessed from the service layer?

Copy link
Contributor

Choose a reason for hiding this comment

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

@atrocitytheme , I unresolved this comment as it is still valid. VolumeService is accessible and SnapshotService can easily be added to the UserVmServiceImpl. no reason to pass them.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see you did apply this in UserVmManagerImpl but didn't remove the parameters.

} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
catch (ResourceAllocationException | InsufficientCapacityException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
}
Comment on lines +148 to +158
Copy link
Contributor

Choose a reason for hiding this comment

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

We could improve these logs with some context data and unify the catches.

result.ifPresentOrElse((userVm)-> {
UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result.get()).get(0);
response.setResponseName("full_clone");
setResponseObject(response);
}, ()-> {
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, "failed to clone VM: " + getId());
});
}

@Override
public String getCommandName() {
return s_name;
}

@Override
public long getEntityOwnerId() {
UserVm vm = this._responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();
}
return Account.ACCOUNT_ID_SYSTEM;
}

public UserVm getTargetVM() {
return this._userVmService.getUserVm(getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ public SnapshotResult takeSnapshot(SnapshotInfo snap) {

try {
result = future.get();
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_ON_PRIMARY, snap.getAccountId(), snap.getDataCenterId(), snap.getId(),
snap.getName(), null, null, snapshotOnPrimary.getSize(), snapshotOnPrimary.getSize(), snap.getClass().getName(), snap.getUuid());
SnapshotVO snapVO = _snapshotDao.findById(snap.getId());
if (snapVO == null || snapVO.getSnapshotType() != Snapshot.Type.INTERNAL.ordinal()) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_ON_PRIMARY, snap.getAccountId(), snap.getDataCenterId(), snap.getId(),
snap.getName(), null, null, snapshotOnPrimary.getSize(), snapshotOnPrimary.getSize(), snap.getClass().getName(), snap.getUuid());
}
return result;
} catch (InterruptedException e) {
s_logger.debug("Failed to create snapshot", e);
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/com/cloud/network/NetworkModelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

import javax.inject.Inject;
import javax.naming.ConfigurationException;
Expand Down Expand Up @@ -845,6 +846,15 @@ public List<NetworkVO> listNetworksUsedByVm(long vmId, boolean isSystem) {
return networks;
}

@Override
public List<Long> listNetworksUsedByVm(long vmId) {
return listNetworksUsedByVm(vmId, false).
stream().
mapToLong(NetworkVO::getId).
boxed().
collect(Collectors.toList());
}

@Override
public Nic getNicInNetwork(long vmId, long networkId) {
return _nicDao.findByNtwkIdAndInstanceId(networkId, vmId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@
import org.apache.cloudstack.api.command.user.userdata.RegisterUserDataCmd;
import org.apache.cloudstack.api.command.user.vm.AddIpToVmNicCmd;
import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd;
import org.apache.cloudstack.api.command.user.vm.CloneVMCmd;
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
import org.apache.cloudstack.api.command.user.vm.GetVMPasswordCmd;
Expand Down Expand Up @@ -3486,6 +3487,7 @@ public List<Class<?>> getCommands() {
cmdList.add(ExpungeVMCmd.class);
cmdList.add(GetVMPasswordCmd.class);
cmdList.add(ListVMsCmd.class);
cmdList.add(CloneVMCmd.class);
cmdList.add(ScaleVMCmd.class);
cmdList.add(RebootVMCmd.class);
cmdList.add(RemoveNicFromVMCmd.class);
Expand Down
Loading