From fcd39839f8f7078dcc8d3d470f04413806543b4c Mon Sep 17 00:00:00 2001 From: nvazquez Date: Wed, 2 May 2018 22:41:11 -0300 Subject: [PATCH] Backup and Recovery Framework and DummyProvider --- api/src/main/java/com/cloud/host/Host.java | 2 +- .../apache/cloudstack/api/ApiConstants.java | 5 + client/pom.xml | 10 + .../spring-core-registry-core-context.xml | 4 + .../META-INF/db/schema-41110to41200.sql | 30 +- framework/backup-and-recovery/pom.xml | 60 ++++ .../backuprecovery/BackupRecoveryManager.java | 28 ++ .../BackupRecoveryProvider.java | 60 ++++ .../backuprecovery/BackupRecoveryService.java | 59 ++++ .../api/AssignVMToBackupPolicyAnswer.java | 30 ++ .../api/AssignVMToBackupPolicyCommand.java | 52 +++ .../agent/api/CheckBackupPolicyAnswer.java | 29 ++ .../agent/api/CheckBackupPolicyCommand.java | 39 +++ .../agent/api/ImportBackupPoliciesAnswer.java | 39 +++ .../api/ImportBackupPoliciesCommand.java | 30 ++ .../agent/api/ListBackupPoliciesAnswer.java | 40 +++ .../agent/api/ListBackupPoliciesCommand.java | 40 +++ .../agent/api/ListBackupsAnswer.java | 39 +++ .../agent/api/ListBackupsCommand.java | 40 +++ .../agent/api/RestoreVMFromBackupAnswer.java | 30 ++ .../agent/api/RestoreVMFromBackupCommand.java | 58 ++++ .../StartupBackupRecoveryProviderCommand.java | 28 ++ .../agent/api/to/BackupPolicyTO.java | 47 +++ .../api/AddBackupRecoveryPolicyCmd.java | 96 ++++++ .../api/AddBackupRecoveryProviderCmd.java | 135 ++++++++ .../api/AssignBackupPolicyCmd.java | 98 ++++++ .../api/DeleteBackupRecoveryProviderCmd.java | 90 +++++ .../api/ListBackupRecoveryPoliciesCmd.java | 89 +++++ ...ListBackupRecoveryProviderPoliciesCmd.java | 85 +++++ .../api/ListBackupRecoveryProvidersCmd.java | 97 ++++++ .../api/response/BackupPolicyResponse.java | 61 ++++ .../BackupRecoveryProviderPolicyResponse.java | 53 +++ .../BackupRecoveryProviderResponse.java | 69 ++++ .../backuprecovery/dao/BackupPoliciesDao.java | 28 ++ .../dao/BackupRecoveryProviderDao.java | 28 ++ .../element/BackupRecoveryElement.java | 79 +++++ .../element/BackupRecoveryElementService.java | 25 ++ .../helper/BackupRecoveryHelper.java | 49 +++ .../impl/BackupPoliciesDaoImpl.java | 50 +++ .../backuprecovery/impl/BackupPolicyVO.java | 103 ++++++ .../impl/BackupRecoveryManagerImpl.java | 323 ++++++++++++++++++ .../impl/BackupRecoveryProviderDaoImpl.java | 58 ++++ .../impl/BackupRecoveryProviderVO.java | 125 +++++++ .../resource/BackupRecoveryResource.java | 155 +++++++++ .../backup-and-recovery/module.properties | 21 ++ .../spring-backup-and-recovery-context.xml | 37 ++ framework/pom.xml | 1 + plugins/backup-and-recovery/dummy/pom.xml | 36 ++ .../element/DummyBackupRecoveryElement.java | 40 +++ .../resource/DummyBackupRecoveryResource.java | 100 ++++++ .../dummy-backup-recovery/module.properties | 19 ++ .../spring-dummy-backup-recovery-context.xml | 28 ++ plugins/pom.xml | 1 + tools/apidoc/gen_toc.py | 3 +- 54 files changed, 2978 insertions(+), 3 deletions(-) create mode 100644 framework/backup-and-recovery/pom.xml create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryManager.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryProvider.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryService.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/AssignVMToBackupPolicyAnswer.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/AssignVMToBackupPolicyCommand.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/CheckBackupPolicyAnswer.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/CheckBackupPolicyCommand.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ImportBackupPoliciesAnswer.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ImportBackupPoliciesCommand.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupPoliciesAnswer.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupPoliciesCommand.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupsAnswer.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupsCommand.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/RestoreVMFromBackupAnswer.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/RestoreVMFromBackupCommand.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/StartupBackupRecoveryProviderCommand.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/to/BackupPolicyTO.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AddBackupRecoveryPolicyCmd.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AddBackupRecoveryProviderCmd.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AssignBackupPolicyCmd.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/DeleteBackupRecoveryProviderCmd.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryPoliciesCmd.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryProviderPoliciesCmd.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryProvidersCmd.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupPolicyResponse.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupRecoveryProviderPolicyResponse.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupRecoveryProviderResponse.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/dao/BackupPoliciesDao.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/dao/BackupRecoveryProviderDao.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/element/BackupRecoveryElement.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/element/BackupRecoveryElementService.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/helper/BackupRecoveryHelper.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupPoliciesDaoImpl.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupPolicyVO.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryManagerImpl.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryProviderDaoImpl.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryProviderVO.java create mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/resource/BackupRecoveryResource.java create mode 100644 framework/backup-and-recovery/src/main/resources/META-INF/cloudstack/backup-and-recovery/module.properties create mode 100644 framework/backup-and-recovery/src/main/resources/META-INF/cloudstack/backup-and-recovery/spring-backup-and-recovery-context.xml create mode 100644 plugins/backup-and-recovery/dummy/pom.xml create mode 100644 plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/backuprecovery/element/DummyBackupRecoveryElement.java create mode 100644 plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/backuprecovery/resource/DummyBackupRecoveryResource.java create mode 100644 plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/module.properties create mode 100644 plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/spring-dummy-backup-recovery-context.xml diff --git a/api/src/main/java/com/cloud/host/Host.java b/api/src/main/java/com/cloud/host/Host.java index 1ecd48d74ce..a8c0b4b8ed6 100644 --- a/api/src/main/java/com/cloud/host/Host.java +++ b/api/src/main/java/com/cloud/host/Host.java @@ -33,7 +33,7 @@ public interface Host extends StateObject, Identity, Partition, HAResour Storage(false), Routing(false), SecondaryStorage(false), SecondaryStorageCmdExecutor(false), ConsoleProxy(true), ExternalFirewall(false), ExternalLoadBalancer( false), ExternalVirtualSwitchSupervisor(false), PxeServer(false), BaremetalPxe(false), BaremetalDhcp(false), TrafficMonitor(false), NetScalerControlCenter(false), - ExternalDhcp(false), SecondaryStorageVM(true), LocalSecondaryStorage(false), L2Networking(false); + ExternalDhcp(false), SecondaryStorageVM(true), LocalSecondaryStorage(false), L2Networking(false), BackupRecovery(true); boolean _virtual; private Type(boolean virtual) { diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java index 504b2149837..9d783cd7081 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java @@ -719,6 +719,11 @@ public class ApiConstants { public static final String LAST_ANNOTATED = "lastannotated"; public static final String LDAP_DOMAIN = "ldapdomain"; + // Backup and Recovery + public static final String BACKUP_PROVIDER_ID = "backupproviderid"; + public static final String BACKUP_POLICY_ID = "backuppolicyid"; + public static final String BACKUP_POLICY_NAME = "backuppolicyname"; + public enum HostDetails { all, capacity, events, stats, min; } diff --git a/client/pom.xml b/client/pom.xml index 7a11972ec3b..db2f5be1785 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -473,6 +473,16 @@ cloud-plugin-integrations-prometheus-exporter ${project.version} + + org.apache.cloudstack + cloud-framework-backup-and-recovery + ${project.version} + + + org.apache.cloudstack + cloud-plugin-backup-and-recovery-dummy + ${project.version} + diff --git a/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml b/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml index 1f70e526147..186f37fe13c 100644 --- a/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml +++ b/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml @@ -323,4 +323,8 @@ class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry"> + + + diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41110to41200.sql b/engine/schema/src/main/resources/META-INF/db/schema-41110to41200.sql index d5e6d61ea71..aaefbd03b32 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41110to41200.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41110to41200.sql @@ -32,4 +32,32 @@ ALTER TABLE `vlan` CHANGE `description` `ip4_range` varchar(255); -- We are only adding the permission to the default rules. Any custom rule must be configured by the root admin. INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 2, 'moveNetworkAclItem', 'ALLOW', 100) ON DUPLICATE KEY UPDATE rule=rule; INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 3, 'moveNetworkAclItem', 'ALLOW', 302) ON DUPLICATE KEY UPDATE rule=rule; -INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 4, 'moveNetworkAclItem', 'ALLOW', 260) ON DUPLICATE KEY UPDATE rule=rule; \ No newline at end of file +INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 4, 'moveNetworkAclItem', 'ALLOW', 260) ON DUPLICATE KEY UPDATE rule=rule; + +-- Backup and Recovery + +CREATE TABLE IF NOT EXISTS `cloud`.`backup_and_recovery_providers` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `uuid` varchar(40), + `name` varchar(255) COMMENT 'name for the backup and recovery provider', + `url` varchar(255) DEFAULT NULL COMMENT 'the url of the backup and recovery provider', + `zone_id` bigint unsigned NOT NULL COMMENT 'foreign key to zone id', + `host_id` bigint(20) unsigned NOT NULL COMMENT 'host id coresponding to the backup and recovery provider', + `provider` varchar(255) DEFAULT NULL COMMENT 'the backup and recovery provider', + PRIMARY KEY (`id`), + UNIQUE KEY `uuid` (`uuid`), + KEY `fk_backup_and_recovery_providers__host_id` (`host_id`), + CONSTRAINT `fk_backup_and_recovery_providers__host_id` FOREIGN KEY (`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_backup_and_recovery_providers__zone_id` FOREIGN KEY (`zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `cloud`.`backup_policies` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `uuid` varchar(40) NOT NULL, + `provider_id` bigint(20) unsigned NOT NULL COMMENT 'backup and recovery provider id', + `name` varchar(255) NOT NULL COMMENT 'backup policy name', + `policy_uuid` varchar(40) NOT NULL COMMENT 'backup policy ID on provider side', + PRIMARY KEY (`id`), + UNIQUE KEY `uuid` (`uuid`), + CONSTRAINT `fk_backup_polocies__provider_id` FOREIGN KEY (`provider_id`) REFERENCES `backup_and_recovery_providers` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/framework/backup-and-recovery/pom.xml b/framework/backup-and-recovery/pom.xml new file mode 100644 index 00000000000..4edeb358361 --- /dev/null +++ b/framework/backup-and-recovery/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + cloud-framework-backup-and-recovery + Apache CloudStack Framework - Backup and Recovery + + cloudstack-framework + org.apache.cloudstack + 4.12.0.0-SNAPSHOT + ../pom.xml + + + + org.apache.cloudstack + cloud-api + ${project.version} + + + org.apache.cloudstack + cloud-core + ${project.version} + + + org.apache.cloudstack + cloud-engine-components-api + 4.12.0.0-SNAPSHOT + compile + + + org.apache.cloudstack + cloud-server + 4.12.0.0-SNAPSHOT + compile + + + org.apache.cloudstack + cloud-server + 4.12.0.0-SNAPSHOT + compile + + + \ No newline at end of file diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryManager.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryManager.java new file mode 100644 index 00000000000..790bcc5c636 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryManager.java @@ -0,0 +1,28 @@ +// 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.framework.backuprecovery; + +import com.cloud.utils.component.PluggableService; +import org.apache.cloudstack.framework.config.Configurable; + +/** + * Backup and Recover Manager Interface + */ +public interface BackupRecoveryManager extends BackupRecoveryService, BackupRecoveryProvider, Configurable, PluggableService { + +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryProvider.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryProvider.java new file mode 100644 index 00000000000..c7a4fbb24f8 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryProvider.java @@ -0,0 +1,60 @@ +// 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.framework.backuprecovery; + +import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.utils.component.Adapter; +import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryPolicyCmd; +import org.apache.cloudstack.framework.backuprecovery.api.AssignBackupPolicyCmd; +import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryPoliciesCmd; +import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProviderPoliciesCmd; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO; + +import java.util.List; + +/** + * Backup and Recovery Provider + */ +public interface BackupRecoveryProvider extends Adapter { + + /** + * List existing Backup Policies on the provider + */ + List listBackupPolicies(ListBackupRecoveryProviderPoliciesCmd cmd) throws AgentUnavailableException, OperationTimedoutException; + + /** + * List backup policies mapped to provider policies + */ + List listBackupPolicies(ListBackupRecoveryPoliciesCmd cmd); + + /** + * Add a Backup Policy by mapping it to a policy on the provider + */ + BackupPolicyVO addBackupPolicy(AddBackupRecoveryPolicyCmd cmd) throws AgentUnavailableException, OperationTimedoutException; + + /** + * Assign a VM to an existing backup policy + */ + boolean assignVMToBackupPolicy(AssignBackupPolicyCmd cmd) throws AgentUnavailableException, OperationTimedoutException; + + void restoreVMFromBackup(); + void restoreAndAttachVolumeToVM(); + +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryService.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryService.java new file mode 100644 index 00000000000..5e91684cab7 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/BackupRecoveryService.java @@ -0,0 +1,59 @@ +// 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.framework.backuprecovery; + +import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryProviderCmd; +import org.apache.cloudstack.framework.backuprecovery.api.DeleteBackupRecoveryProviderCmd; +import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProvidersCmd; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +public interface BackupRecoveryService { + + /** + * Add a new Backup and Recovery provider + */ + BackupRecoveryProviderVO addBackupRecoveryProvider(AddBackupRecoveryProviderCmd cmd) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException; + + /** + * Delete existing Backup and Recovery provider + */ + boolean deleteBackupRecoveryProvider(DeleteBackupRecoveryProviderCmd cmd); + + /** + * List existing Backup and Recovery providers + * @param cmd + * @return + */ + List listBackupRecoveryProviders(ListBackupRecoveryProvidersCmd cmd); + + /** + * Generate a response from the Backup and Recovery Provider VO + */ + BackupRecoveryProviderResponse createBackupRecoveryProviderResponse(BackupRecoveryProviderVO backupRecoveryProviderVO); + + /** + * Generate a response from the Backup Policy VO + */ + BackupPolicyResponse createBackupPolicyResponse(BackupPolicyVO policyVO); +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/AssignVMToBackupPolicyAnswer.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/AssignVMToBackupPolicyAnswer.java new file mode 100644 index 00000000000..95eec6f142a --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/AssignVMToBackupPolicyAnswer.java @@ -0,0 +1,30 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Answer; + +public class AssignVMToBackupPolicyAnswer extends Answer { + + public AssignVMToBackupPolicyAnswer(final boolean result) { + super(null); + this.result = result; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/AssignVMToBackupPolicyCommand.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/AssignVMToBackupPolicyCommand.java new file mode 100644 index 00000000000..f25fbac4316 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/AssignVMToBackupPolicyCommand.java @@ -0,0 +1,52 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Command; + +public class AssignVMToBackupPolicyCommand extends Command { + + private long vmId; + private String vmUuid; + private String backupPolicyUuid; + + public AssignVMToBackupPolicyCommand(final long vmId, final String vmUuid, final String backupPolicyUuid) { + this.vmId = vmId; + this.vmUuid = vmUuid; + this.backupPolicyUuid = backupPolicyUuid; + } + + public long getVmId() { + return vmId; + } + + public String getVmUuid() { + return vmUuid; + } + + public String getBackupPolicyUuid() { + return backupPolicyUuid; + } + + @Override + public boolean executeInSequence() { + return false; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/CheckBackupPolicyAnswer.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/CheckBackupPolicyAnswer.java new file mode 100644 index 00000000000..bda887c710f --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/CheckBackupPolicyAnswer.java @@ -0,0 +1,29 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Answer; + +public class CheckBackupPolicyAnswer extends Answer { + + public CheckBackupPolicyAnswer(final boolean result) { + super(null); + this.result = result; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/CheckBackupPolicyCommand.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/CheckBackupPolicyCommand.java new file mode 100644 index 00000000000..44138358fdf --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/CheckBackupPolicyCommand.java @@ -0,0 +1,39 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Command; + +public class CheckBackupPolicyCommand extends Command { + + private String policyUuid; + + public CheckBackupPolicyCommand(final String policyUuid) { + this.policyUuid = policyUuid; + } + + public String getPolicyUuid() { + return policyUuid; + } + + @Override + public boolean executeInSequence() { + return false; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ImportBackupPoliciesAnswer.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ImportBackupPoliciesAnswer.java new file mode 100644 index 00000000000..aee63466708 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ImportBackupPoliciesAnswer.java @@ -0,0 +1,39 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Answer; + +import java.util.List; + +public class ImportBackupPoliciesAnswer extends Answer { + + private List backupPolicies; + + public ImportBackupPoliciesAnswer(final boolean result, final List backupPolicies) { + super(null); + this.result = result; + this.backupPolicies = backupPolicies; + } + + public List getBackupPolicies() { + return backupPolicies; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ImportBackupPoliciesCommand.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ImportBackupPoliciesCommand.java new file mode 100644 index 00000000000..a907993c29f --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ImportBackupPoliciesCommand.java @@ -0,0 +1,30 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Command; + +public class ImportBackupPoliciesCommand extends Command { + + @Override + public boolean executeInSequence() { + return false; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupPoliciesAnswer.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupPoliciesAnswer.java new file mode 100644 index 00000000000..7e958b56a4e --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupPoliciesAnswer.java @@ -0,0 +1,40 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Answer; +import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO; + +import java.util.List; + +public class ListBackupPoliciesAnswer extends Answer { + + private List policies; + + public ListBackupPoliciesAnswer(final boolean result, final List policies) { + super(null); + this.result = result; + this.policies = policies; + } + + public List getPolicies() { + return policies; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupPoliciesCommand.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupPoliciesCommand.java new file mode 100644 index 00000000000..5efc7b1d021 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupPoliciesCommand.java @@ -0,0 +1,40 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Command; + +public class ListBackupPoliciesCommand extends Command { + + private String zoneUuid; + + @Override + public boolean executeInSequence() { + return false; + } + + public ListBackupPoliciesCommand(String zoneUuid) { + this.zoneUuid = zoneUuid; + } + + public String getZoneUuid() { + return zoneUuid; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupsAnswer.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupsAnswer.java new file mode 100644 index 00000000000..a03f8bb11de --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupsAnswer.java @@ -0,0 +1,39 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Answer; + +import java.util.List; + +public class ListBackupsAnswer extends Answer { + + private List backups; + + public ListBackupsAnswer(final boolean result, final List backups) { + super(null); + this.result = result; + this.backups = backups; + } + + public List getBackups() { + return backups; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupsCommand.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupsCommand.java new file mode 100644 index 00000000000..cc37c00dfbc --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/ListBackupsCommand.java @@ -0,0 +1,40 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Command; + +public class ListBackupsCommand extends Command { + + private Long vmId; + + public ListBackupsCommand(final Long vmId) { + this.vmId = vmId; + } + + public Long getVmId() { + return vmId; + } + + @Override + public boolean executeInSequence() { + return false; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/RestoreVMFromBackupAnswer.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/RestoreVMFromBackupAnswer.java new file mode 100644 index 00000000000..6a933706300 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/RestoreVMFromBackupAnswer.java @@ -0,0 +1,30 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Answer; + +public class RestoreVMFromBackupAnswer extends Answer { + + public RestoreVMFromBackupAnswer(final boolean result) { + super(null); + this.result = result; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/RestoreVMFromBackupCommand.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/RestoreVMFromBackupCommand.java new file mode 100644 index 00000000000..67eaac12b6d --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/RestoreVMFromBackupCommand.java @@ -0,0 +1,58 @@ +/* + * 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.Command; + +public class RestoreVMFromBackupCommand extends Command { + + private long vmId; + private String vmUuid; + private long backupId; + private String backupUuid; + + public RestoreVMFromBackupCommand(final long vmId, final String vmUuid, final long backupId, final String backupUuid) { + this.vmId = vmId; + this.vmUuid = vmUuid; + this.backupId = backupId; + this.backupUuid = backupUuid; + } + + public long getVmId() { + return vmId; + } + + public String getVmUuid() { + return vmUuid; + } + + public long getBackupId() { + return backupId; + } + + public String getBackupUuid() { + return backupUuid; + } + + @Override + public boolean executeInSequence() { + return false; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/StartupBackupRecoveryProviderCommand.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/StartupBackupRecoveryProviderCommand.java new file mode 100644 index 00000000000..a7376f63e06 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/StartupBackupRecoveryProviderCommand.java @@ -0,0 +1,28 @@ +// 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.framework.backuprecovery.agent.api; + +import com.cloud.agent.api.StartupCommand; +import com.cloud.host.Host; + +public class StartupBackupRecoveryProviderCommand extends StartupCommand { + + public StartupBackupRecoveryProviderCommand() { + super(Host.Type.BackupRecovery); + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/to/BackupPolicyTO.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/to/BackupPolicyTO.java new file mode 100644 index 00000000000..7b73ea5a1c1 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/agent/api/to/BackupPolicyTO.java @@ -0,0 +1,47 @@ +/* + * 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.framework.backuprecovery.agent.api.to; + +import java.io.Serializable; + +public class BackupPolicyTO implements Serializable { + + private String name; + private String id; + private String description; + + public BackupPolicyTO(final String id, final String name, final String desc) { + this.id = id; + this.name = name; + this.description = desc; + } + + public String getName() { + return name; + } + + public String getId() { + return id; + } + + public String getDescription() { + return description; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AddBackupRecoveryPolicyCmd.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AddBackupRecoveryPolicyCmd.java new file mode 100644 index 00000000000..0cc10874eae --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AddBackupRecoveryPolicyCmd.java @@ -0,0 +1,96 @@ +package org.apache.cloudstack.framework.backuprecovery.api; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO; + +import javax.inject.Inject; + +@APICommand(name = AddBackupRecoveryPolicyCmd.APINAME, + description = "Adds a Backup policy", + responseObject = BackupPolicyResponse.class, since = "4.12.0", + authorized = {RoleType.Admin}) +public class AddBackupRecoveryPolicyCmd extends BaseCmd { + + public static final String APINAME = "addBackupRecoveryPolicy"; + + @Inject + BackupRecoveryManager backupRecoveryManager; + + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the policy") + private String policyName; + + @Parameter(name = ApiConstants.BACKUP_POLICY_ID, + type = CommandType.STRING, + entityType = BackupRecoveryProviderResponse.class, + required = true, + description = "Backup Recovery Provider ID") + private String policyId; + + @Parameter(name = ApiConstants.BACKUP_PROVIDER_ID, + type = BaseCmd.CommandType.UUID, + entityType = BackupRecoveryProviderResponse.class, + required = true, + description = "Backup Recovery Provider ID") + private Long providerId; + + public String getPolicyName() { + return policyName; + } + + public String getPolicyId() { + return policyId; + } + + public Long getProviderId() { + return providerId; + } + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + BackupPolicyVO policyVO = backupRecoveryManager.addBackupPolicy(this); + if (policyVO != null) { + BackupPolicyResponse response = backupRecoveryManager.createBackupPolicyResponse(policyVO); + response.setObjectName("backuppolicy"); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add a Backup policy"); + } + } catch (InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); + } catch (CloudRuntimeException e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } catch (OperationTimedoutException e) { + e.printStackTrace(); + } + } + + @Override + public String getCommandName() { + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AddBackupRecoveryProviderCmd.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AddBackupRecoveryProviderCmd.java new file mode 100644 index 00000000000..fd54ac7a2b8 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AddBackupRecoveryProviderCmd.java @@ -0,0 +1,135 @@ +// 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.framework.backuprecovery.api; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO; +import org.apache.log4j.Logger; + +import javax.inject.Inject; +import java.lang.reflect.InvocationTargetException; + +@APICommand(name = AddBackupRecoveryProviderCmd.APINAME, + description = "Adds a Backup and Recovery provider on a zone", + responseObject = BackupRecoveryProviderResponse.class, since = "4.12.0", + authorized = {RoleType.Admin}) +public class AddBackupRecoveryProviderCmd extends BaseCmd { + + public static final String APINAME = "addBackupRecoveryProvider"; + + private static final Logger s_logger = Logger.getLogger(AddBackupRecoveryProviderCmd.class); + + @Inject + BackupRecoveryManager backupRecoveryManager; + + @Parameter(name=ApiConstants.ZONE_ID, type=BaseCmd.CommandType.UUID, entityType = ZoneResponse.class, + required=true, description="the ID of the zone you wish to register the Backup and Recovery provider to.") + private Long zoneId; + + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the Backup and Recovery provider") + private String name; + + @Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, length = 2048, description = "the URL of the Backup and Recovery provider portal") + private String url; + + @Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "the username for the Backup and Recovery provider") + private String username; + + @Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "the password for the Backup and Recovery provider") + private String password; + + @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true, description = "the Backup and Recovery provider type") + private String provider; + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + BackupRecoveryProviderVO providerVO = backupRecoveryManager.addBackupRecoveryProvider(this); + if (providerVO != null) { + BackupRecoveryProviderResponse response = backupRecoveryManager.createBackupRecoveryProviderResponse(providerVO); + response.setObjectName("backuprecoveryprovider"); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add a Backup and Recovery Provider"); + } + } catch (InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); + } catch (CloudRuntimeException e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + @Override + public String getCommandName() { + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + public Long getZoneId() { + return zoneId; + } + + public String getName() { + return name; + } + + public String getUrl() { + return url; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getProvider() { + return provider; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AssignBackupPolicyCmd.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AssignBackupPolicyCmd.java new file mode 100644 index 00000000000..7cd79041382 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/AssignBackupPolicyCmd.java @@ -0,0 +1,98 @@ +/* + * 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.framework.backuprecovery.api; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; + +import javax.inject.Inject; + +@APICommand(name = AssignBackupPolicyCmd.APINAME, + description = "Assigns a VM to an existing backup policy", + responseObject = SuccessResponse.class, since = "4.12.0") +public class AssignBackupPolicyCmd extends BaseCmd { + + public static final String APINAME = "assignBackupPolicy"; + + @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, + type = CommandType.UUID, + entityType = UserVmResponse.class, + required = true, + description = "id of the VM to be moved") + private Long virtualMachineId; + + @Parameter(name = ApiConstants.BACKUP_POLICY_ID, + type = CommandType.STRING, + entityType = BackupRecoveryProviderResponse.class, + required = true, + description = "Backup Recovery Provider ID") + private String policyId; + + public Long getVirtualMachineId() { + return virtualMachineId; + } + + public String getPolicyId() { + return policyId; + } + + @Inject + BackupRecoveryManager backupRecoveryManager; + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + boolean result = backupRecoveryManager.assignVMToBackupPolicy(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign VM to backup policy"); + } + } catch (Exception e) { + + } + } + + @Override + public String getCommandName() { + return AssignBackupPolicyCmd.APINAME + BaseCmd.RESPONSE_SUFFIX; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/DeleteBackupRecoveryProviderCmd.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/DeleteBackupRecoveryProviderCmd.java new file mode 100644 index 00000000000..183ceed3b7b --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/DeleteBackupRecoveryProviderCmd.java @@ -0,0 +1,90 @@ +// 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.framework.backuprecovery.api; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; + +import javax.inject.Inject; + +@APICommand(name = DeleteBackupRecoveryProviderCmd.APINAME, + description = "Deletes a Backup and Recovery provider", + responseObject = SuccessResponse.class, since = "4.12.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class DeleteBackupRecoveryProviderCmd extends BaseCmd { + + public static final String APINAME = "deleteBackupRecoveryProvider"; + + @Inject + BackupRecoveryManager backupRecoveryManager; + + @Parameter(name = ApiConstants.BACKUP_PROVIDER_ID, + type = CommandType.UUID, + entityType = BackupRecoveryProviderResponse.class, + required = true, + description = "Backup Recovery Provider ID") + private Long providerId; + + public Long getProviderId() { + return providerId; + } + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + boolean result = backupRecoveryManager.deleteBackupRecoveryProvider(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Backup and Recovery Provider"); + } + } catch (InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); + } catch (CloudRuntimeException e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } + } + + @Override + public String getCommandName() { + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryPoliciesCmd.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryPoliciesCmd.java new file mode 100644 index 00000000000..f0b43e4dddf --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryPoliciesCmd.java @@ -0,0 +1,89 @@ +// 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.framework.backuprecovery.api; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO; +import org.apache.commons.collections.CollectionUtils; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +@APICommand(name = ListBackupRecoveryPoliciesCmd.APINAME, + description = "Lists mapped Backup policies", + responseObject = BackupPolicyResponse.class, since = "4.12.0", + authorized = {RoleType.Admin}) +public class ListBackupRecoveryPoliciesCmd extends BaseListCmd { + + public static final String APINAME = "listBackupRecoveryPolicies"; + + @Parameter(name = ApiConstants.BACKUP_PROVIDER_ID, + type = BaseCmd.CommandType.UUID, + entityType = BackupRecoveryProviderResponse.class, + required = true, + description = "Backup Recovery Provider ID") + private Long providerId; + + public long getProviderId() { + return providerId; + } + + @Inject + BackupRecoveryManager backupRecoveryManager; + + @Override + public void execute() throws ServerApiException, ConcurrentOperationException { + try { + ListResponse response = new ListResponse(); + List responses = new ArrayList<>(); + List policies = backupRecoveryManager.listBackupPolicies(this); + if (CollectionUtils.isNotEmpty(policies)) { + for (BackupPolicyVO policy : policies) { + BackupPolicyResponse p = backupRecoveryManager.createBackupPolicyResponse(policy); + responses.add(p); + } + } + response.setResponses(responses, responses.size()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); + } catch (CloudRuntimeException e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } + } + @Override + public String getCommandName() { + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; + } + +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryProviderPoliciesCmd.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryProviderPoliciesCmd.java new file mode 100644 index 00000000000..5a41aa46a4f --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryProviderPoliciesCmd.java @@ -0,0 +1,85 @@ +// 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.framework.backuprecovery.api; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; + +import javax.inject.Inject; +import java.util.List; + +@APICommand(name = ListBackupRecoveryProviderPoliciesCmd.APINAME, + description = "Lists Backup policies existing on the Backup and Recovery provider side", + responseObject = BackupRecoveryProviderPolicyResponse.class, since = "4.12.0", + authorized = {RoleType.Admin}) +public class ListBackupRecoveryProviderPoliciesCmd extends BaseListCmd { + + public static final String APINAME = "listBackupRecoveryProviderPolicies"; + + @Inject + BackupRecoveryManager backupRecoveryManager; + + @Parameter(name = ApiConstants.BACKUP_PROVIDER_ID, + type = BaseCmd.CommandType.UUID, + entityType = BackupRecoveryProviderResponse.class, + required = true, + description = "Backup Recovery Provider ID") + private Long providerId; + + public Long getProviderId() { + return providerId; + } + + @Override + public void execute() throws ResourceUnavailableException, ServerApiException, ConcurrentOperationException { + try { + ListResponse response = new ListResponse(); + List policies = backupRecoveryManager.listBackupPolicies(this); + if (policies == null) { + throw new CloudRuntimeException("Error while retrieving backup provider policies"); + } + response.setResponses(policies, policies.size()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); + } catch (CloudRuntimeException | OperationTimedoutException e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } + } + + @Override + public String getCommandName() { + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryProvidersCmd.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryProvidersCmd.java new file mode 100644 index 00000000000..cff2a893cb8 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/ListBackupRecoveryProvidersCmd.java @@ -0,0 +1,97 @@ +// 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.framework.backuprecovery.api; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO; +import org.apache.commons.collections.CollectionUtils; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +@APICommand(name = ListBackupRecoveryProvidersCmd.APINAME, + description = "Lists Backup and Recovery providers", + responseObject = BackupRecoveryProviderResponse.class, since = "4.12.0", + authorized = {RoleType.Admin}) +public class ListBackupRecoveryProvidersCmd extends BaseListCmd { + + public static final String APINAME = "listBackupRecoveryProviders"; + + @Inject + BackupRecoveryManager backupRecoveryManager; + + @Parameter(name=ApiConstants.ZONE_ID, type=BaseCmd.CommandType.UUID, entityType = ZoneResponse.class, + description="the ID of the zone") + private Long zoneId; + + @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, entityType = BackupRecoveryProviderResponse.class, + description = "the Backup and Recovery provider type") + private String provider; + + public Long getZoneId() { + return zoneId; + } + + public String getProvider() { + return provider; + } + + @Override + public void execute() throws ServerApiException, ConcurrentOperationException { + try { + List providers = backupRecoveryManager.listBackupRecoveryProviders(this); + ListResponse response = new ListResponse(); + List providersResponse = new ArrayList(); + + if (CollectionUtils.isNotEmpty(providers)) { + for (BackupRecoveryProviderVO providerVO : providers) { + BackupRecoveryProviderResponse providerResponse = backupRecoveryManager.createBackupRecoveryProviderResponse(providerVO); + providersResponse.add(providerResponse); + } + } + + response.setResponses(providersResponse, providersResponse.size()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); + } catch (CloudRuntimeException e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } + } + + @Override + public String getCommandName() { + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupPolicyResponse.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupPolicyResponse.java new file mode 100644 index 00000000000..e980a1b76a7 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupPolicyResponse.java @@ -0,0 +1,61 @@ +// 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.framework.backuprecovery.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO; + +@EntityReference(value = BackupPolicyVO.class) +public class BackupPolicyResponse extends BaseResponse { + + @SerializedName(ApiConstants.ID) + @Param(description = "internal id of the Backup policy") + private String id; + + @SerializedName(ApiConstants.BACKUP_POLICY_ID) + @Param(description = "policy id on the provider side") + private String policyId; + + @SerializedName(ApiConstants.BACKUP_PROVIDER_ID) + @Param(description = "id of the Backup and Recovery provider") + private String providerId; + + @SerializedName(ApiConstants.BACKUP_POLICY_NAME) + @Param(description = "internal name for the backup policy") + private String name; + + public void setId(String id) { + this.id = id; + } + + public void setPolicyId(String policyId) { + this.policyId = policyId; + } + + public void setProviderId(String providerId) { + this.providerId = providerId; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupRecoveryProviderPolicyResponse.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupRecoveryProviderPolicyResponse.java new file mode 100644 index 00000000000..1c3813cb245 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupRecoveryProviderPolicyResponse.java @@ -0,0 +1,53 @@ +// 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.framework.backuprecovery.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +/** + * Response for a Backup Policy on the provider + */ +public class BackupRecoveryProviderPolicyResponse extends BaseResponse { + + @SerializedName(ApiConstants.BACKUP_POLICY_ID) + @Param(description = "policy id on the provider side") + private String policyId; + + @SerializedName(ApiConstants.BACKUP_POLICY_NAME) + @Param(description = "name for the backup policy on the provider side") + private String name; + + @SerializedName(ApiConstants.DESCRIPTION) + @Param(description = "description for the backup policy on the provider side") + private String description; + + public void setPolicyId(String policyId) { + this.policyId = policyId; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String desc) { + this.description = desc; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupRecoveryProviderResponse.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupRecoveryProviderResponse.java new file mode 100644 index 00000000000..b454e5b67d5 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/api/response/BackupRecoveryProviderResponse.java @@ -0,0 +1,69 @@ +// 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.framework.backuprecovery.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO; + +@EntityReference(value = BackupRecoveryProviderVO.class) +public class BackupRecoveryProviderResponse extends BaseResponse { + + @SerializedName(ApiConstants.BACKUP_PROVIDER_ID) + @Param(description = "id of the Backup and Recovery provider") + private String id; + + @SerializedName(ApiConstants.PROVIDER) + @Param(description = "name of the provider") + private String providerName; + + @SerializedName(ApiConstants.NAME) + @Param(description = "internal name for the Backup and Recovery provider") + private String name; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "id of the zone") + private String zoneId; + + @SerializedName(ApiConstants.HOST_ID) + @Param(description = "id of the host") + private String hostId; + + public void setId(String id) { + this.id = id; + } + + public void setProviderName(String providerName) { + this.providerName = providerName; + } + + public void setName(String name) { + this.name = name; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public void setHostId(String hostId) { + this.hostId = hostId; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/dao/BackupPoliciesDao.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/dao/BackupPoliciesDao.java new file mode 100644 index 00000000000..7f6421e4f79 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/dao/BackupPoliciesDao.java @@ -0,0 +1,28 @@ +// 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.framework.backuprecovery.dao; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO; + +import java.util.List; + +public interface BackupPoliciesDao extends GenericDao { + + List listByProvider(long providerId); +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/dao/BackupRecoveryProviderDao.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/dao/BackupRecoveryProviderDao.java new file mode 100644 index 00000000000..2eb70ee1b38 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/dao/BackupRecoveryProviderDao.java @@ -0,0 +1,28 @@ +// 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.framework.backuprecovery.dao; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO; + +import java.util.List; + +public interface BackupRecoveryProviderDao extends GenericDao { + + List listByZone(long zoneId); + List listByZoneAndProvider(long zoneId, String provider); +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/element/BackupRecoveryElement.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/element/BackupRecoveryElement.java new file mode 100644 index 00000000000..8d089a95547 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/element/BackupRecoveryElement.java @@ -0,0 +1,79 @@ +/* + * 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.framework.backuprecovery.element; + +import com.cloud.agent.api.StartupCommand; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.resource.ResourceManager; +import com.cloud.resource.ResourceStateAdapter; +import com.cloud.resource.ServerResource; +import com.cloud.resource.UnableDeleteHostException; +import com.cloud.utils.component.AdapterBase; +import org.apache.cloudstack.framework.backuprecovery.agent.api.StartupBackupRecoveryProviderCommand; +import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; +import java.util.List; +import java.util.Map; + +/** + * Backup and Recovery Element class. + * To register a Backup and Recovery element, just extend this class + */ +public class BackupRecoveryElement extends AdapterBase implements ResourceStateAdapter, BackupRecoveryElementService { + + @Inject + ResourceManager resourceManager; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + resourceManager.registerResourceStateAdapter(name, this); + return true; + } + + @Override + public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { + return null; + } + + @Override + public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map details, List hostTags) { + if (!(startup[0] instanceof StartupBackupRecoveryProviderCommand)) { + return null; + } + host.setType(Host.Type.BackupRecovery); + return host; + } + + @Override + public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { + if (!(host.getType() == Host.Type.BackupRecovery)) { + return null; + } + return new DeleteHostAnswer(true); + } + + @Override + public BackupRecoveryResource createNewResource() { + return new BackupRecoveryResource(); + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/element/BackupRecoveryElementService.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/element/BackupRecoveryElementService.java new file mode 100644 index 00000000000..fcfaaa86094 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/element/BackupRecoveryElementService.java @@ -0,0 +1,25 @@ +// 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.framework.backuprecovery.element; + +import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource; + +public interface BackupRecoveryElementService { + + BackupRecoveryResource createNewResource(); +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/helper/BackupRecoveryHelper.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/helper/BackupRecoveryHelper.java new file mode 100644 index 00000000000..458908ac7cf --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/helper/BackupRecoveryHelper.java @@ -0,0 +1,49 @@ +// 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.framework.backuprecovery.helper; + +import org.apache.cloudstack.framework.backuprecovery.element.BackupRecoveryElement; +import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource; + +import java.util.HashMap; +import java.util.Map; + +public class BackupRecoveryHelper { + + /** + * Backup and Recovery Providers Helper + */ + + private static Map supportedProviders = new HashMap(); + + public static boolean isProviderSupported(String providerName) { + return supportedProviders.containsKey(providerName); + } + + public static void addProvider(String providerName, BackupRecoveryElement element) { + supportedProviders.put(providerName, element); + } + + public static BackupRecoveryResource getResource(String name) { + if (supportedProviders.containsKey(name)) { + BackupRecoveryElement element = supportedProviders.get(name); + return element.createNewResource(); + } + return null; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupPoliciesDaoImpl.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupPoliciesDaoImpl.java new file mode 100644 index 00000000000..624f6888299 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupPoliciesDaoImpl.java @@ -0,0 +1,50 @@ +// 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.framework.backuprecovery.impl; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import org.apache.cloudstack.framework.backuprecovery.dao.BackupPoliciesDao; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.List; + +@Component +public class BackupPoliciesDaoImpl extends GenericDaoBase implements BackupPoliciesDao { + + protected SearchBuilder backupPoliciesSearch; + + public BackupPoliciesDaoImpl() { + } + + @PostConstruct + protected void init() { + backupPoliciesSearch = createSearchBuilder(); + backupPoliciesSearch.and("provider", backupPoliciesSearch.entity().getProviderId(), SearchCriteria.Op.EQ); + backupPoliciesSearch.done(); + } + + @Override + public List listByProvider(long providerId) { + SearchCriteria sc = backupPoliciesSearch.create(); + sc.setParameters("provider", providerId); + return listBy(sc); + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupPolicyVO.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupPolicyVO.java new file mode 100644 index 00000000000..a691e934b30 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupPolicyVO.java @@ -0,0 +1,103 @@ +// 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.framework.backuprecovery.impl; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.UUID; + +@Entity +@Table(name = "backup_policies") +public class BackupPolicyVO implements InternalIdentity, Identity { + + public BackupPolicyVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public BackupPolicyVO(final long providerId, final String name, final String policyUuid) { + this(); + this.providerId = providerId; + this.name = name; + this.policyUuid = policyUuid; + } + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "provider_id") + private long providerId; + + @Column(name = "name") + private String name; + + @Column(name = "policy_uuid") + private String policyUuid; + + @Override + public String getUuid() { + return null; + } + + @Override + public long getId() { + return 0; + } + + public void setId(long id) { + this.id = id; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPolicyUuid() { + return policyUuid; + } + + public void setPolicyUuid(String policyUuid) { + this.policyUuid = policyUuid; + } + + public long getProviderId() { + return providerId; + } + + public void setProviderId(long providerId) { + this.providerId = providerId; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryManagerImpl.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryManagerImpl.java new file mode 100644 index 00000000000..41a74cd592f --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryManagerImpl.java @@ -0,0 +1,323 @@ +// 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.framework.backuprecovery.impl; + +import com.cloud.agent.AgentManager; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.host.DetailVO; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.host.dao.HostDetailsDao; +import com.cloud.resource.ResourceManager; +import com.cloud.resource.ResourceState; +import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import com.cloud.utils.db.TransactionStatus; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.dao.VMInstanceDao; +import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager; +import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyAnswer; +import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyCommand; +import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyAnswer; +import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyCommand; +import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesAnswer; +import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesCommand; +import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO; +import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryPolicyCmd; +import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryProviderCmd; +import org.apache.cloudstack.framework.backuprecovery.api.AssignBackupPolicyCmd; +import org.apache.cloudstack.framework.backuprecovery.api.DeleteBackupRecoveryProviderCmd; +import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryPoliciesCmd; +import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProviderPoliciesCmd; +import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProvidersCmd; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse; +import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse; +import org.apache.cloudstack.framework.backuprecovery.dao.BackupPoliciesDao; +import org.apache.cloudstack.framework.backuprecovery.dao.BackupRecoveryProviderDao; +import org.apache.cloudstack.framework.backuprecovery.helper.BackupRecoveryHelper; +import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; +import java.lang.reflect.InvocationTargetException; +import java.security.InvalidParameterException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.ArrayList; + +public class BackupRecoveryManagerImpl extends ManagerBase implements BackupRecoveryManager { + + @Inject + BackupRecoveryProviderDao backupRecoveryProviderDao; + @Inject + HostDetailsDao hostDetailsDao; + @Inject + ResourceManager resourceManager; + @Inject + HostDao hostDao; + @Inject + DataCenterDao dataCenterDao; + @Inject + BackupPoliciesDao backupPoliciesDao; + @Inject + AgentManager agentManager; + @Inject + VMInstanceDao vmInstanceDao; + + private static final Logger s_logger = Logger.getLogger(BackupRecoveryManagerImpl.class); + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + return true; + } + + @Override + public BackupRecoveryProviderVO addBackupRecoveryProvider(AddBackupRecoveryProviderCmd cmd) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + String name = cmd.getName(); + String url = cmd.getUrl(); + String username = cmd.getUsername(); + String password = cmd.getPassword(); + Long zoneId = cmd.getZoneId(); + String providerName = cmd.getProvider(); + + if (!BackupRecoveryHelper.isProviderSupported(providerName)) { + throw new InvalidParameterException("Unsopported provider: " + providerName); + } + + s_logger.debug("Registering a new Backup and Recovery provider on zone: " + zoneId + " - url: " + url + " - name: " + name + + " - provider: " + providerName); + BackupRecoveryResource resource = BackupRecoveryHelper.getResource(providerName); + + Map params = new HashMap(); + params.put("guid", UUID.randomUUID().toString()); + params.put("zoneId", String.valueOf(zoneId)); + params.put("name", name + " - " + url); + //params.put("ip", cmd.getHost()); + params.put("adminuser", username); + params.put("adminpass", password); + params.put("url", url); + + Map hostdetails = new HashMap(); + hostdetails.putAll(params); + try { + resource.configure(name, hostdetails); + } catch (ConfigurationException e) { + throw new CloudRuntimeException(e.getMessage()); + } + + final Host host = resourceManager.addHost(zoneId, resource, Host.Type.BackupRecovery, params); + if (host != null) { + return Transaction.execute(new TransactionCallback() { + @Override + public BackupRecoveryProviderVO doInTransaction(TransactionStatus status) { + BackupRecoveryProviderVO providerVO = new BackupRecoveryProviderVO(host.getId(), name, zoneId, url, providerName); + providerVO = backupRecoveryProviderDao.persist(providerVO); + + DetailVO detail = new DetailVO(host.getId(), "providerid", String.valueOf(providerVO.getId())); + hostDetailsDao.persist(detail); + + return providerVO; + } + }); + } else { + throw new CloudRuntimeException("Failed to add the Backup and Recovery provider " + providerName + " - " + name); + } + } + + @Override + public boolean deleteBackupRecoveryProvider(DeleteBackupRecoveryProviderCmd cmd) { + Long providerId = cmd.getProviderId(); + BackupRecoveryProviderVO providerVO = backupRecoveryProviderDao.findById(providerId); + if (providerVO == null) { + throw new InvalidParameterValueException("Could not find a Backup and Recovery provider with id: " + providerId); + } + + HostVO host = hostDao.findById(providerVO.getHostId()); + + host.setResourceState(ResourceState.Maintenance); + hostDao.update(host.getId(), host); + resourceManager.deleteHost(host.getId(), false, false); + + backupRecoveryProviderDao.remove(providerId); + return true; + } + + @Override + public List listBackupRecoveryProviders(ListBackupRecoveryProvidersCmd cmd) { + Long zoneId = cmd.getZoneId(); + String providerName = cmd.getProvider(); + + if (zoneId == null) { + throw new InvalidParameterException("Must specify a zone id"); + } + + if (StringUtils.isNotBlank(providerName)) { + if (!BackupRecoveryHelper.isProviderSupported(providerName)) { + throw new InvalidParameterException("Unsopported provider: " + providerName); + } + backupRecoveryProviderDao.listByZoneAndProvider(zoneId, providerName); + } + return backupRecoveryProviderDao.listByZone(zoneId); + } + + @Override + public BackupRecoveryProviderResponse createBackupRecoveryProviderResponse(BackupRecoveryProviderVO vo) { + HostVO host = hostDao.findById(vo.getHostId()); + DataCenterVO dc = dataCenterDao.findById(vo.getZoneId()); + + BackupRecoveryProviderResponse response = new BackupRecoveryProviderResponse(); + response.setHostId(host.getUuid()); + response.setId(vo.getUuid()); + response.setName(vo.getName()); + response.setProviderName(vo.getProviderName()); + response.setZoneId(dc.getUuid()); + return response; + } + + @Override + public BackupPolicyResponse createBackupPolicyResponse(BackupPolicyVO policyVO) { + BackupRecoveryProviderVO provider = backupRecoveryProviderDao.findById(policyVO.getProviderId()); + + BackupPolicyResponse response = new BackupPolicyResponse(); + response.setId(policyVO.getUuid()); + response.setPolicyId(policyVO.getPolicyUuid()); + response.setName(policyVO.getName()); + response.setProviderId(provider.getUuid()); + return response; + } + + @Override + public List> getCommands() { + final List> cmdList = new ArrayList>(); + cmdList.add(AddBackupRecoveryProviderCmd.class); + cmdList.add(DeleteBackupRecoveryProviderCmd.class); + cmdList.add(ListBackupRecoveryProvidersCmd.class); + cmdList.add(ListBackupRecoveryPoliciesCmd.class); + cmdList.add(ListBackupRecoveryProviderPoliciesCmd.class); + cmdList.add(AddBackupRecoveryPolicyCmd.class); + return cmdList; + } + + @Override + public String getConfigComponentName() { + return null; + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[0]; + } + + @Override + public List listBackupPolicies(ListBackupRecoveryProviderPoliciesCmd cmd) throws AgentUnavailableException, OperationTimedoutException { + Long providerId = cmd.getProviderId(); + BackupRecoveryProviderVO providerVO = backupRecoveryProviderDao.findById(providerId); + if (providerVO == null) { + throw new InvalidParameterValueException("Could not find a Backup and Recovery provider with id: " + cmd.getProviderId()); + } + + if (!BackupRecoveryHelper.isProviderSupported(providerVO.getProviderName())) { + throw new InvalidParameterValueException("Provider: " + providerVO.getProviderName() + " is not supported"); + } + + DataCenterVO zone = dataCenterDao.findById(providerVO.getZoneId()); + ListBackupPoliciesCommand command = new ListBackupPoliciesCommand(zone.getUuid()); + ListBackupPoliciesAnswer answer = (ListBackupPoliciesAnswer) agentManager.send(providerVO.getHostId(), command); + + if (answer != null && answer.getResult()) { + return createBackupRecoveryProviderPoliciesResponse(answer.getPolicies()); + } + return null; + } + + private List createBackupRecoveryProviderPoliciesResponse(List policies) { + List list = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(policies)) { + for (BackupPolicyTO policy : policies) { + BackupRecoveryProviderPolicyResponse p = new BackupRecoveryProviderPolicyResponse(); + p.setName(policy.getName()); + p.setPolicyId(policy.getId()); + p.setDescription(policy.getDescription()); + list.add(p); + } + } + return list; + } + + @Override + public List listBackupPolicies(ListBackupRecoveryPoliciesCmd cmd) { + return backupPoliciesDao.listByProvider(cmd.getProviderId()); + } + + @Override + public BackupPolicyVO addBackupPolicy(AddBackupRecoveryPolicyCmd cmd) throws AgentUnavailableException, OperationTimedoutException { + String policyId = cmd.getPolicyId(); + Long providerId = cmd.getProviderId(); + String name = cmd.getPolicyName(); + + BackupRecoveryProviderVO provider = backupRecoveryProviderDao.findById(providerId); + if (provider == null) { + throw new InvalidParameterValueException("Could not find a Backup and Recovery provider with id: " + providerId); + } + + CheckBackupPolicyCommand command = new CheckBackupPolicyCommand(policyId); + CheckBackupPolicyAnswer answer = (CheckBackupPolicyAnswer) agentManager.send(provider.getHostId(), command); + if (answer == null || !answer.getResult()) { + throw new InvalidParameterValueException("Could not find a backup policy with id: " + policyId + " on the provider"); + } + BackupPolicyVO policy = new BackupPolicyVO(providerId, name, policyId); + return backupPoliciesDao.persist(policy); + } + + @Override + public boolean assignVMToBackupPolicy(AssignBackupPolicyCmd cmd) throws AgentUnavailableException, OperationTimedoutException { + String policyId = cmd.getPolicyId(); + Long virtualMachineId = cmd.getVirtualMachineId(); + VMInstanceVO vm = vmInstanceDao.findById(virtualMachineId); + BackupPolicyVO policy = backupPoliciesDao.findByUuid(policyId); + BackupRecoveryProviderVO provider = backupRecoveryProviderDao.findById(policy.getProviderId()); + + AssignVMToBackupPolicyCommand command = new AssignVMToBackupPolicyCommand(virtualMachineId, vm.getUuid(), policyId); + AssignVMToBackupPolicyAnswer answer = (AssignVMToBackupPolicyAnswer) agentManager.send(provider.getHostId(), command); + return answer != null && answer.getResult(); + } + + @Override + public void restoreVMFromBackup() { + + } + + @Override + public void restoreAndAttachVolumeToVM() { + + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryProviderDaoImpl.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryProviderDaoImpl.java new file mode 100644 index 00000000000..c1e3c207aec --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryProviderDaoImpl.java @@ -0,0 +1,58 @@ +// 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.framework.backuprecovery.impl; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import org.apache.cloudstack.framework.backuprecovery.dao.BackupRecoveryProviderDao; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.List; + +@Component +public class BackupRecoveryProviderDaoImpl extends GenericDaoBase implements BackupRecoveryProviderDao { + + protected SearchBuilder backupProviderSearch; + + public BackupRecoveryProviderDaoImpl() { + } + + @PostConstruct + protected void init() { + backupProviderSearch = createSearchBuilder(); + backupProviderSearch.and("zoneid", backupProviderSearch.entity().getZoneId(), SearchCriteria.Op.EQ); + backupProviderSearch.and("provider", backupProviderSearch.entity().getProviderName(), SearchCriteria.Op.EQ); + backupProviderSearch.done(); + } + + @Override + public List listByZone(long zoneId) { + SearchCriteria sc = backupProviderSearch.create(); + sc.setParameters("zoneid", zoneId); + return listBy(sc); + } + + @Override + public List listByZoneAndProvider(long zoneId, String provider) { + SearchCriteria sc = backupProviderSearch.create(); + sc.setParameters("zoneid", zoneId); + sc.setParameters("provider", provider); + return listBy(sc); + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryProviderVO.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryProviderVO.java new file mode 100644 index 00000000000..e93d95a10dd --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/impl/BackupRecoveryProviderVO.java @@ -0,0 +1,125 @@ +// 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.framework.backuprecovery.impl; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Column; +import javax.persistence.GenerationType; +import java.util.UUID; + +@Entity +@Table(name = "backup_and_recovery_providers") +public class BackupRecoveryProviderVO implements InternalIdentity, Identity { + + public BackupRecoveryProviderVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public BackupRecoveryProviderVO(final long hostId, final String name, final long zoneId, final String url, final String provider) { + this(); + this.name = name; + this.zoneId = zoneId; + this.hostId = hostId; + this.provider = provider; + this.url = url; + } + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "host_id") + private long hostId; + + @Column(name = "name") + private String name; + + @Column(name = "url", length = 2048) + private String url; + + @Column(name = "zone_id") + private long zoneId; + + @Column(name = "provider") + private String provider; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public long getHostId() { + return hostId; + } + + public void setHostId(long hostId) { + this.hostId = hostId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public long getZoneId() { + return zoneId; + } + + public void setZoneId(long zoneId) { + this.zoneId = zoneId; + } + + public String getProviderName() { + return provider; + } + + public void setProviderName(String provider) { + this.provider = provider; + } +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/resource/BackupRecoveryResource.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/resource/BackupRecoveryResource.java new file mode 100644 index 00000000000..2c38f0512e7 --- /dev/null +++ b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/backuprecovery/resource/BackupRecoveryResource.java @@ -0,0 +1,155 @@ +// 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.framework.backuprecovery.resource; + +import com.cloud.agent.IAgentControl; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.PingCommand; +import com.cloud.agent.api.StartupCommand; +import com.cloud.host.Host; +import com.cloud.resource.ServerResource; +import org.apache.cloudstack.framework.backuprecovery.agent.api.StartupBackupRecoveryProviderCommand; +import org.apache.commons.collections.MapUtils; +import org.apache.log4j.Logger; + +import javax.naming.ConfigurationException; +import java.util.Map; + +public class BackupRecoveryResource implements ServerResource { + + private static final Logger s_logger = Logger.getLogger(BackupRecoveryResource.class); + private String name; + private String zoneId; + private String guid; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + if (MapUtils.isNotEmpty(params)) { + this.name = (String) params.get("name"); + if (this.name == null) { + throw new ConfigurationException("Unable to find name"); + } + + zoneId = (String) params.get("zoneId"); + if (zoneId == null) { + throw new ConfigurationException("Unable to find zone"); + } + + guid = (String) params.get("guid"); + if (guid == null) { + throw new ConfigurationException("Unable to find guid"); + } + + /*final String ip = (String) params.get("ip"); + if (ip == null) { + throw new ConfigurationException("Unable to find IP"); + }*/ + + final String adminuser = (String) params.get("adminuser"); + if (adminuser == null) { + throw new ConfigurationException("Unable to find admin username"); + } + + final String adminpass = (String) params.get("adminpass"); + if (adminpass == null) { + throw new ConfigurationException("Unable to find admin password"); + } + } + return true; + } + + @Override + public Host.Type getType() { + return Host.Type.BackupRecovery; + } + + @Override + public StartupCommand[] initialize() { + final StartupBackupRecoveryProviderCommand sc = new StartupBackupRecoveryProviderCommand(); + sc.setGuid(guid); + sc.setName(name); + sc.setDataCenter(zoneId); + sc.setPod(null); + sc.setPrivateIpAddress(""); + sc.setStorageIpAddress(""); + sc.setVersion(BackupRecoveryResource.class.getPackage().getImplementationVersion()); + return new StartupCommand[] { sc }; + } + + public PingCommand getCurrentStatus(long id) { + return new PingCommand(getType(), id); + } + + public Answer executeRequest(Command cmd) { + s_logger.debug("Received Command: " + cmd.toString()); + Answer answer = new Answer(cmd, true, "response"); + s_logger.debug("Replying with: " + answer.toString()); + return answer; + } + + @Override + public void disconnected() { + } + + @Override + public IAgentControl getAgentControl() { + return null; + } + + @Override + public void setAgentControl(IAgentControl agentControl) { + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + } + + @Override + public void setConfigParams(Map params) { + } + + @Override + public Map getConfigParams() { + return null; + } + + @Override + public int getRunLevel() { + return 0; + } + + @Override + public void setRunLevel(int level) { + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } +} diff --git a/framework/backup-and-recovery/src/main/resources/META-INF/cloudstack/backup-and-recovery/module.properties b/framework/backup-and-recovery/src/main/resources/META-INF/cloudstack/backup-and-recovery/module.properties new file mode 100644 index 00000000000..88aa812add7 --- /dev/null +++ b/framework/backup-and-recovery/src/main/resources/META-INF/cloudstack/backup-and-recovery/module.properties @@ -0,0 +1,21 @@ +# +# 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. +# + +name=backup-and-recovery +parent=backend \ No newline at end of file diff --git a/framework/backup-and-recovery/src/main/resources/META-INF/cloudstack/backup-and-recovery/spring-backup-and-recovery-context.xml b/framework/backup-and-recovery/src/main/resources/META-INF/cloudstack/backup-and-recovery/spring-backup-and-recovery-context.xml new file mode 100644 index 00000000000..17e1d16082c --- /dev/null +++ b/framework/backup-and-recovery/src/main/resources/META-INF/cloudstack/backup-and-recovery/spring-backup-and-recovery-context.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/pom.xml b/framework/pom.xml index 4f0f5cf5364..709e6efbb14 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -58,5 +58,6 @@ security agent-lb direct-download + backup-and-recovery diff --git a/plugins/backup-and-recovery/dummy/pom.xml b/plugins/backup-and-recovery/dummy/pom.xml new file mode 100644 index 00000000000..500dc66d1b7 --- /dev/null +++ b/plugins/backup-and-recovery/dummy/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + cloud-plugin-backup-and-recovery-dummy + Apache CloudStack Plugin - Backup and Recovery Dummy Plugin + + cloudstack-plugins + org.apache.cloudstack + 4.12.0.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-framework-backup-and-recovery + ${project.version} + + + \ No newline at end of file diff --git a/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/backuprecovery/element/DummyBackupRecoveryElement.java b/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/backuprecovery/element/DummyBackupRecoveryElement.java new file mode 100644 index 00000000000..93f521006bc --- /dev/null +++ b/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/backuprecovery/element/DummyBackupRecoveryElement.java @@ -0,0 +1,40 @@ +// 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.backuprecovery.element; + +import org.apache.cloudstack.backuprecovery.resource.DummyBackupRecoveryResource; +import org.apache.cloudstack.framework.backuprecovery.element.BackupRecoveryElement; +import org.apache.cloudstack.framework.backuprecovery.helper.BackupRecoveryHelper; +import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource; + +import javax.naming.ConfigurationException; +import java.util.Map; + +public class DummyBackupRecoveryElement extends BackupRecoveryElement { + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + BackupRecoveryHelper.addProvider("Dummy", this); + return true; + } + + @Override + public BackupRecoveryResource createNewResource() { + return new DummyBackupRecoveryResource(); + } +} diff --git a/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/backuprecovery/resource/DummyBackupRecoveryResource.java b/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/backuprecovery/resource/DummyBackupRecoveryResource.java new file mode 100644 index 00000000000..d87c5b6c4bf --- /dev/null +++ b/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/backuprecovery/resource/DummyBackupRecoveryResource.java @@ -0,0 +1,100 @@ +// 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.backuprecovery.resource; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.StartupCommand; +import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyAnswer; +import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyCommand; +import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyAnswer; +import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyCommand; +import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesAnswer; +import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesCommand; +import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO; +import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource; +import org.apache.log4j.Logger; + +import javax.naming.ConfigurationException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class DummyBackupRecoveryResource extends BackupRecoveryResource { + + private static final Logger s_logger = Logger.getLogger(DummyBackupRecoveryResource.class); + + private BackupPolicyTO policy1 = new BackupPolicyTO("aaaa-aaaa", "Policy A", "Gold policy"); + private BackupPolicyTO policy2 = new BackupPolicyTO("bbbb-bbbb", "Policy B", "Silver policy"); + + private List policies = Arrays.asList(policy1, policy2); + + @Override + public Answer executeRequest(Command cmd) { + + s_logger.debug("Received Command: " + cmd.toString()); + Answer answer = new Answer(cmd, true, "response"); + if (cmd instanceof ListBackupPoliciesCommand) { + answer = execute((ListBackupPoliciesCommand) cmd); + } else if (cmd instanceof CheckBackupPolicyCommand) { + answer = execute((CheckBackupPolicyCommand) cmd); + } else if (cmd instanceof AssignVMToBackupPolicyCommand) { + answer = execute((AssignVMToBackupPolicyCommand) cmd); + } + s_logger.debug("Replying with: " + answer.toString()); + return answer; + } + + private Answer execute(AssignVMToBackupPolicyCommand cmd) { + s_logger.debug("Assigning VM " + cmd.getVmUuid() + " to Backup policy: " + cmd.getBackupPolicyUuid()); + return new AssignVMToBackupPolicyAnswer(true); + } + + private Answer execute(CheckBackupPolicyCommand cmd) { + s_logger.debug("Checking if backup policy " + cmd.getPolicyUuid() + " exists"); + boolean result = false; + String policyUuid = cmd.getPolicyUuid(); + for (BackupPolicyTO policy: policies) { + if (policy.getId().equals(policyUuid)) { + result = true; + break; + } + } + return new CheckBackupPolicyAnswer(result); + } + + private Answer execute(ListBackupPoliciesCommand cmd) { + s_logger.debug("Listing existing backup policies"); + return new ListBackupPoliciesAnswer(true, policies); + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + return true; + } + + @Override + public StartupCommand[] initialize() { + return super.initialize(); + } + + @Override + public String getName() { + return "DummyBackupRecoveryProvider"; + } +} diff --git a/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/module.properties b/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/module.properties new file mode 100644 index 00000000000..e4554a31519 --- /dev/null +++ b/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/module.properties @@ -0,0 +1,19 @@ +# 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. + +name=dummy-backup-recovery +parent=backup-and-recovery \ No newline at end of file diff --git a/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/spring-dummy-backup-recovery-context.xml b/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/spring-dummy-backup-recovery-context.xml new file mode 100644 index 00000000000..c697112d997 --- /dev/null +++ b/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/spring-dummy-backup-recovery-context.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/plugins/pom.xml b/plugins/pom.xml index 009577c0e0c..77b6d048f58 100755 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -110,6 +110,7 @@ database/quota integrations/cloudian integrations/prometheus + backup-and-recovery/dummy diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py index a025efefcbc..4c7b2fe4b5c 100644 --- a/tools/apidoc/gen_toc.py +++ b/tools/apidoc/gen_toc.py @@ -190,7 +190,8 @@ known_categories = { 'CA': 'Certificate', 'listElastistorInterface': 'Misc', 'cloudian': 'Cloudian', - 'Sioc' : 'Sioc' + 'Sioc' : 'Sioc', + 'BackupRecovery' : 'BackupRecovery' }