harikrishna-patnala commented on code in PR #7873: URL: https://github.com/apache/cloudstack/pull/7873#discussion_r1320789273
########## api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java: ########## @@ -0,0 +1,184 @@ +// 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.snapshot; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +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.SnapshotResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.commons.collections.CollectionUtils; +import org.apache.log4j.Logger; + +import com.cloud.dc.DataCenter; +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.StorageUnavailableException; +import com.cloud.storage.Snapshot; +import com.cloud.user.Account; + +@APICommand(name = "copySnapshot", description = "Copies a snapshot from one zone to another.", responseObject = SnapshotResponse.class, responseView = ResponseObject.ResponseView.Restricted, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class CopySnapshotCmd extends BaseAsyncCmd implements UserCmd { + public static final Logger s_logger = Logger.getLogger(CopySnapshotCmd.class.getName()); + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, + entityType = SnapshotResponse.class, required = true, description = "the ID of the snapshot.") + private Long id; + + @Parameter(name = ApiConstants.SOURCE_ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + description = "ID of the zone in which the snapshot is currently present. " + + "If not specified and zone in which the volume of the snapshot is present will be used.") + private Long sourceZoneId; + + @Parameter(name = ApiConstants.DESTINATION_ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + required = false, + description = "the ID of the zone the snapshot is being copied to.") + protected Long destZoneId; + + @Parameter(name = ApiConstants.DESTINATION_ZONE_ID_LIST, + type=CommandType.LIST, + collectionType = CommandType.UUID, + entityType = ZoneResponse.class, + required = false, + description = "A list of IDs of the zones that the snapshot needs to be copied to." + + "Specify this list if the snapshot needs to copied to multiple zones in one go. " + + "Do not specify destzoneid and destzoneids together, however one of them is required.") + protected List<Long> destZoneIds; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public Long getId() { + return id; + } + + public Long getSourceZoneId() { + return sourceZoneId; + } + + public List<Long> getDestinationZoneIds() { + if (destZoneIds != null && destZoneIds.size() != 0) { + return destZoneIds; + } + if (destZoneId != null) { + List < Long > destIds = new ArrayList<>(); + destIds.add(destZoneId); + return destIds; + } + return null; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_SNAPSHOT_COPY; + } + + @Override + public String getEventDescription() { + StringBuilder descBuilder = new StringBuilder(); + if (getDestinationZoneIds() != null) { + for (Long destId : getDestinationZoneIds()) { + descBuilder.append(", "); + descBuilder.append(this._uuidMgr.getUuid(DataCenter.class, destId)); + } + if (descBuilder.length() > 0) { + descBuilder.deleteCharAt(0); + } + } + + return "copying snapshot: " + this._uuidMgr.getUuid(Snapshot.class, getId()) + ((descBuilder.length() > 0) ? " to zones: " + descBuilder.toString() : ""); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Snapshot; + } + + @Override + public Long getApiResourceId() { + return getId(); + } + + @Override + public long getEntityOwnerId() { + Snapshot snapshot = _entityMgr.findById(Snapshot.class, getId()); + if (snapshot != null) { + return snapshot.getAccountId(); + } + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute() throws ResourceUnavailableException { + try { + if (destZoneId == null && CollectionUtils.isEmpty(destZoneIds)) + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, + "Either destzoneid or destzoneids parameters have to be specified."); + + if (destZoneId != null && CollectionUtils.isNotEmpty(destZoneIds)) + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, + "Both destzoneid and destzoneids cannot be specified at the same time."); + + CallContext.current().setEventDetails(getEventDescription()); + Snapshot snapshot = _snapshotService.copySnapshot(this); + + if (snapshot != null) { +// List<SnapshotResponse> listResponse = new ArrayList<>();_responseGenerator.createSnapshotResponse(getResponseView(), Review Comment: please remove this ########## api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java: ########## @@ -75,6 +77,14 @@ public class CreateSnapshotPolicyCmd extends BaseCmd { @Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "Map of tags (key/value pairs)") private Map tags; + @Parameter(name = ApiConstants.ZONE_ID_LIST, + type=CommandType.LIST, + collectionType = CommandType.UUID, + entityType = ZoneResponse.class, + description = "A list of IDs of the zones in which the snapshots will be made available." + Review Comment: since parameter please ########## engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java: ########## @@ -25,50 +25,51 @@ import java.util.List; import java.util.Map; -import org.junit.Test; - -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.SnapshotOperation; import org.apache.cloudstack.storage.helper.StorageStrategyFactoryImpl; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.host.Host; -import com.cloud.storage.Snapshot; - -public class StrategyPriorityTest { - - @Test - public void testSortSnapshotStrategies() { - SnapshotStrategy cantHandleStrategy = mock(SnapshotStrategy.class); - SnapshotStrategy defaultStrategy = mock(SnapshotStrategy.class); - SnapshotStrategy hyperStrategy = mock(SnapshotStrategy.class); - SnapshotStrategy highestStrategy = mock(SnapshotStrategy.class); - - doReturn(StrategyPriority.CANT_HANDLE).when(cantHandleStrategy).canHandle(any(Snapshot.class), any(SnapshotOperation.class)); - doReturn(StrategyPriority.DEFAULT).when(defaultStrategy).canHandle(any(Snapshot.class), any(SnapshotOperation.class)); - doReturn(StrategyPriority.HYPERVISOR).when(hyperStrategy).canHandle(any(Snapshot.class), any(SnapshotOperation.class)); - doReturn(StrategyPriority.HIGHEST).when(highestStrategy).canHandle(any(Snapshot.class), any(SnapshotOperation.class)); - List<SnapshotStrategy> strategies = new ArrayList<SnapshotStrategy>(5); - SnapshotStrategy strategy = null; - StorageStrategyFactoryImpl factory = new StorageStrategyFactoryImpl(); - factory.setSnapshotStrategies(strategies); - - strategies.add(cantHandleStrategy); - strategy = factory.getSnapshotStrategy(mock(Snapshot.class), SnapshotOperation.TAKE); - assertEquals("A strategy was found when it shouldn't have been.", null, strategy); - - strategies.add(defaultStrategy); - strategy = factory.getSnapshotStrategy(mock(Snapshot.class), SnapshotOperation.TAKE); - assertEquals("Default strategy was not picked.", defaultStrategy, strategy); - - strategies.add(hyperStrategy); - strategy = factory.getSnapshotStrategy(mock(Snapshot.class), SnapshotOperation.TAKE); - assertEquals("Hypervisor strategy was not picked.", hyperStrategy, strategy); +@RunWith(MockitoJUnitRunner.class) +public class StrategyPriorityTest { - strategies.add(highestStrategy); - strategy = factory.getSnapshotStrategy(mock(Snapshot.class), SnapshotOperation.TAKE); - assertEquals("Highest strategy was not picked.", highestStrategy, strategy); - } +// @Test Review Comment: is this something to be deleted or needs update ? ########## api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java: ########## @@ -90,6 +92,14 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "Map of tags (key/value pairs)") private Map tags; + @Parameter(name = ApiConstants.ZONE_ID_LIST, Review Comment: since parameter please ########## api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java: ########## @@ -48,6 +49,10 @@ public class DeleteSnapshotCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = SnapshotResponse.class, required=true, description="The ID of the snapshot") private Long id; + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, Review Comment: "since" parameter please ########## api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java: ########## @@ -0,0 +1,184 @@ +// 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.snapshot; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +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.SnapshotResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.commons.collections.CollectionUtils; +import org.apache.log4j.Logger; + +import com.cloud.dc.DataCenter; +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.StorageUnavailableException; +import com.cloud.storage.Snapshot; +import com.cloud.user.Account; + +@APICommand(name = "copySnapshot", description = "Copies a snapshot from one zone to another.", responseObject = SnapshotResponse.class, responseView = ResponseObject.ResponseView.Restricted, Review Comment: since parameter please ########## plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java: ########## @@ -589,6 +589,7 @@ public Answer executeRequest(Command cmd) { } else if (clz == UnregisterVMCommand.class) { return execute((UnregisterVMCommand) cmd); } else if (cmd instanceof StorageSubSystemCommand) { + s_logger.info("=====================will be handled by storageHandler - " + storageHandler.getClass().getSimpleName()); Review Comment: this info needs to be updated or part of your testing ? ########## api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java: ########## @@ -75,6 +77,14 @@ public class CreateSnapshotPolicyCmd extends BaseCmd { @Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "Map of tags (key/value pairs)") private Map tags; + @Parameter(name = ApiConstants.ZONE_ID_LIST, + type=CommandType.LIST, + collectionType = CommandType.UUID, + entityType = ZoneResponse.class, + description = "A list of IDs of the zones in which the snapshots will be made available." + Review Comment: is this comma separated list of UUIDs ? if so, can you add that in the description ########## api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java: ########## @@ -44,6 +44,9 @@ public class ListZonesCmd extends BaseListCmd implements UserCmd { @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "the ID of the zone") private Long id; + @Parameter(name = ApiConstants.IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = ZoneResponse.class, description = "the IDs of the zones, mutually exclusive with id", since = "4.19") Review Comment: 4.19.0, just to be consistent ########## plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java: ########## @@ -202,4 +212,29 @@ protected Answer execute(CopyCommand cmd) { } } + @Override + protected Answer execute(QuerySnapshotZoneCopyCommand cmd) { + SnapshotObjectTO snapshot = cmd.getSnapshot(); + String parentPath = storageResource.getRootDir(snapshot.getDataStore().getUrl(), _nfsVersion); + String path = snapshot.getPath(); + int index = path.lastIndexOf(File.separator); +// String name = path.substring(index + 1); + String snapDir = path.substring(0, index); +// int timeout = NumbersUtil.parseInt(cmd.getContextParam(VmwareManager.s_vmwareOVAPackageTimeout.key()), Review Comment: delete this please ########## engine/storage/src/test/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImplTest.java: ########## @@ -74,4 +76,10 @@ public void testGetValidGreaterSizeBypassedTemplateOneRecordInvalidState() { TemplateDataStoreVO ref = dao.getValidGreaterSizeBypassedTemplate(List.of(ref1), templateId); Assert.assertNull(ref); } + + @Test + public void test123() { Review Comment: are we testing something here ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
