DaanHoogland commented on code in PR #8796: URL: https://github.com/apache/cloudstack/pull/8796#discussion_r1547516734
########## plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/snapshot/LinstorVMSnapshotStrategy.java: ########## @@ -0,0 +1,361 @@ +// +//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.storage.snapshot; + +import com.linbit.linstor.api.ApiException; +import com.linbit.linstor.api.DevelopersApi; +import com.linbit.linstor.api.model.ApiCallRcList; +import com.linbit.linstor.api.model.CreateMultiSnapshotRequest; +import com.linbit.linstor.api.model.Snapshot; + +import javax.inject.Inject; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.cloud.agent.api.VMSnapshotTO; +import com.cloud.event.EventTypes; +import com.cloud.event.UsageEventUtils; +import com.cloud.storage.DiskOfferingVO; +import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.DiskOfferingDao; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.uservm.UserVm; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.fsm.NoTransitionException; +import com.cloud.vm.UserVmVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.dao.UserVmDao; +import com.cloud.vm.snapshot.VMSnapshot; +import com.cloud.vm.snapshot.VMSnapshotVO; +import com.cloud.vm.snapshot.dao.VMSnapshotDao; +import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.apache.cloudstack.storage.datastore.util.LinstorUtil; +import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.apache.cloudstack.storage.vmsnapshot.DefaultVMSnapshotStrategy; +import org.apache.cloudstack.storage.vmsnapshot.VMSnapshotHelper; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public class LinstorVMSnapshotStrategy extends DefaultVMSnapshotStrategy { + private static final Logger log = Logger.getLogger(LinstorVMSnapshotStrategy.class); + + @Inject + private VMSnapshotHelper _vmSnapshotHelper; + @Inject + private UserVmDao _userVmDao; + @Inject + private VMSnapshotDao vmSnapshotDao; + @Inject + private VolumeDao volumeDao; + @Inject + private DiskOfferingDao diskOfferingDao; + @Inject + private PrimaryDataStoreDao _storagePoolDao; + + private void linstorCreateMultiSnapshot( + DevelopersApi api, VMSnapshotVO vmSnapshotVO, List<VolumeObjectTO> volumeTOs) + throws ApiException { + CreateMultiSnapshotRequest cmsReq = new CreateMultiSnapshotRequest(); + for (VolumeObjectTO vol : volumeTOs) { + Snapshot snap = new Snapshot(); + snap.setName(vmSnapshotVO.getName()); + snap.setResourceName(LinstorUtil.RSC_PREFIX + vol.getPath()); + log.debug(String.format("Add volume %s;%s to snapshot", vol.getName(), snap.getResourceName())); + cmsReq.addSnapshotsItem(snap); + } + log.debug(String.format("Creating multi snapshot %s", vmSnapshotVO.getName())); + ApiCallRcList answers = api.createMultiSnapshot(cmsReq); + log.debug(String.format("Created multi snapshot %s", vmSnapshotVO.getName())); + if (answers.hasError()) { + throw new CloudRuntimeException( + "Error creating vm snapshots: " + LinstorUtil.getBestErrorMessage(answers)); + } + } + + @Override + public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { Review Comment: this method is rather complex @rp- , any chance you can disect it for readability? (no :-1: ) -- 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]
