nvazquez commented on a change in pull request #3553: [WIP] [DO NOT MERGE] 
CloudStack Backup & Recovery Framework
URL: https://github.com/apache/cloudstack/pull/3553#discussion_r357927868
 
 

 ##########
 File path: 
plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java
 ##########
 @@ -0,0 +1,136 @@
+// 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.backup;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.backup.dao.BackupDao;
+import org.apache.log4j.Logger;
+
+import com.cloud.utils.Pair;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
+
+public class DummyBackupProvider extends AdapterBase implements BackupProvider 
{
+
+    private static final Logger s_logger = 
Logger.getLogger(DummyBackupProvider.class);
+
+    @Inject
+    private BackupDao backupDao;
+
+    @Override
+    public String getName() {
+        return "dummy";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Dummy Backup Plugin";
+    }
+
+    @Override
+    public List<BackupOffering> listBackupOfferings(Long zoneId) {
+        s_logger.debug("Listing backup policies on Dummy B&R Plugin");
+        BackupOffering policy1 = new BackupOfferingVO(1, "gold-policy", 
"dummy", "Golden Policy", "Gold description", true);
+        BackupOffering policy2 = new BackupOfferingVO(1, "silver-policy", 
"dummy", "Silver Policy", "Silver description", true);
+        return Arrays.asList(policy1, policy2);
+    }
+
+    @Override
+    public boolean isBackupOffering(Long zoneId, String uuid) {
+        s_logger.debug("Checking if backup offering exists on the Dummy Backup 
Provider");
+        return true;
+    }
+
+    @Override
+    public boolean assignVMToBackupOffering(VirtualMachine vm, BackupOffering 
backupOffering) {
+        s_logger.debug("Creating VM backup for VM " + vm.getInstanceName() + " 
from backup offering " + backupOffering.getName());
+        return true;
+    }
+
+    @Override
+    public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
+        s_logger.debug("Restoring vm " + vm.getUuid() + "from backup " + 
backup.getUuid() + " on the Dummy Backup Provider");
+        return true;
+    }
+
+    @Override
+    public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String 
volumeUuid, String hostIp, String dataStoreUuid) {
+        s_logger.debug("Restoring volume " + volumeUuid + "from backup " + 
backup.getUuid() + " on the Dummy Backup Provider");
+        throw new CloudRuntimeException("Dummy plugin does not support this 
feature");
+    }
+
+    @Override
+    public Map<VirtualMachine, Backup.Metric> getBackupMetrics(Long zoneId, 
List<VirtualMachine> vms) {
+        final Map<VirtualMachine, Backup.Metric> metrics = new HashMap<>();
+        final Backup.Metric metric = new Backup.Metric(1000L, 100L);
+        for (VirtualMachine vm : vms) {
+            metrics.put(vm, metric);
+        }
+        return metrics;
+    }
+
+    @Override
+    public boolean removeVMFromBackupOffering(VirtualMachine vm) {
+        s_logger.debug("Removing VM ID " + vm.getUuid() + " from backup 
offering by the Dummy Backup Provider");
+        final List<Backup> backups = backupDao.listByVmId(null, vm.getId());
+        for (final Backup backup : backups) {
+            backupDao.remove(backup.getId());
 
 Review comment:
   If assignVMToBackupOffering does nothing then why we try to remove the VM 
here? Can we just return true as well?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to