From 68eb42b83c35d669d7037e589af658a1f8f4e980 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Mon, 14 May 2018 16:08:14 +0530 Subject: [PATCH] new refactor and simplifications, add veeam plugin skeleton/stub Signed-off-by: Rohit Yadav --- api/pom.xml | 2 +- .../apache/cloudstack/api/ApiConstants.java | 4 - .../admin/br/policy/AssignBRPolicyCmd.java | 98 ------- .../admin/br/policy/ListBRPoliciesCmd.java | 86 ------ .../admin/br/provider/AddBRProviderCmd.java | 118 -------- .../admin/br/provider/ListBRProvidersCmd.java | 78 ------ .../backup/AssignBackupPolicyCmd.java} | 82 +++--- .../command/user/backup/CreateBackupCmd.java | 20 ++ .../backup/CreateBackupPolicyCmd.java} | 54 ++-- .../command/user/backup/DeleteBackupCmd.java | 20 ++ .../user/backup/DeleteBackupPolicyCmd.java | 8 +- .../backup/ListBackupPoliciesCmd.java} | 51 ++-- .../user/backup/ListBackupProvidersCmd.java | 99 +++++++ .../command/user/backup/ListBackupsCmd.java | 11 +- .../command/user/backup/RestoreBackupCmd.java | 21 ++ ...esponse.java => BackupPolicyResponse.java} | 16 +- ...ponse.java => BackupProviderResponse.java} | 46 +--- .../cloudstack/backup/BackupManager.java | 60 ++++ .../BackupProviderDriver.java} | 13 +- .../org/apache/cloudstack/br/BRManager.java | 58 ---- client/pom.xml | 9 +- .../module.properties | 4 +- ...-lifecycle-backup-context-inheritable.xml} | 6 +- .../spring-core-registry-core-context.xml | 2 +- .../BackupPolicyTO.java} | 15 +- .../BackupPolicyVO.java} | 27 +- .../dao/BackupPolicyDao.java} | 11 +- .../dao/BackupPolicyDaoImpl.java} | 36 +-- .../cloudstack/br/BRProviderDetailVO.java | 81 ------ .../apache/cloudstack/br/BRProviderVO.java | 112 -------- .../cloudstack/br/dao/BRProviderDaoImpl.java | 58 ---- .../br/dao/BRProviderDetailsDao.java | 12 - .../br/dao/BRProviderDetailsDaoImpl.java | 53 ---- ...spring-engine-schema-core-daos-context.xml | 4 +- .../META-INF/db/schema-41110to41200.sql | 29 +- .../cloudstack/framework/br/BRPolicy.java | 29 -- .../framework/br/BRPolicyService.java | 19 -- .../cloudstack/framework/br/BRProvider.java | 10 - .../framework/br/BRProviderService.java | 24 -- .../{backup-and-recovery => backup}/pom.xml | 4 +- .../framework/backup/BackupPolicy.java | 24 ++ .../framework/backup/BackupProvider.java | 32 +++ .../framework/backup/BackupService.java | 39 +++ framework/pom.xml | 2 +- .../apache/cloudstack/br/DummyBRProvider.java | 74 ----- .../dummy/pom.xml | 8 +- .../backup/DummyBackupProvider.java | 34 +++ .../dummy-backup}/module.properties | 5 +- .../spring-backup-dummy-context.xml} | 6 +- plugins/backup/veeam/pom.xml | 36 +++ .../backup/VeeamBackupProvider.java | 70 +++++ .../cloudstack/veeam/module.properties | 18 ++ .../veeam/spring-backup-veeam-context.xml | 27 ++ plugins/pom.xml | 3 +- server/pom.xml | 10 +- .../cloudstack/backup/BackupManagerImpl.java | 139 ++++++++++ .../apache/cloudstack/br/BRManagerImpl.java | 260 ------------------ .../spring-server-core-managers-context.xml | 4 +- tools/apidoc/gen_toc.py | 2 +- 59 files changed, 834 insertions(+), 1449 deletions(-) delete mode 100644 api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/AssignBRPolicyCmd.java delete mode 100644 api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/ListBRPoliciesCmd.java delete mode 100644 api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/AddBRProviderCmd.java delete mode 100644 api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/ListBRProvidersCmd.java rename api/src/main/java/org/apache/cloudstack/api/command/{admin/br/provider/DeleteBRProviderCmd.java => user/backup/AssignBackupPolicyCmd.java} (69%) create mode 100644 api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupCmd.java rename api/src/main/java/org/apache/cloudstack/api/command/{admin/br/policy/AddBRPolicyCmd.java => user/backup/CreateBackupPolicyCmd.java} (76%) create mode 100644 api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupCmd.java rename framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRService.java => api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupPolicyCmd.java (83%) rename api/src/main/java/org/apache/cloudstack/api/command/{admin/br/provider/ListBRProviderPoliciesCmd.java => user/backup/ListBackupPoliciesCmd.java} (69%) create mode 100644 api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupProvidersCmd.java rename engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDao.java => api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java (70%) create mode 100644 api/src/main/java/org/apache/cloudstack/api/command/user/backup/RestoreBackupCmd.java rename api/src/main/java/org/apache/cloudstack/api/response/{BRPolicyResponse.java => BackupPolicyResponse.java} (89%) rename api/src/main/java/org/apache/cloudstack/api/response/{BRProviderResponse.java => BackupProviderResponse.java} (54%) create mode 100644 api/src/main/java/org/apache/cloudstack/backup/BackupManager.java rename api/src/main/java/org/apache/cloudstack/{br/BRProviderDriver.java => backup/BackupProviderDriver.java} (88%) delete mode 100644 api/src/main/java/org/apache/cloudstack/br/BRManager.java rename core/src/main/resources/META-INF/cloudstack/{backup-and-recovery => backup}/module.properties (95%) rename core/src/main/resources/META-INF/cloudstack/{backup-and-recovery/spring-core-lifecycle-backup-and-recovery-context-inheritable.xml => backup/spring-core-lifecycle-backup-context-inheritable.xml} (91%) rename engine/schema/src/main/java/org/apache/cloudstack/{br/BRPolicyTO.java => backup/BackupPolicyTO.java} (76%) rename engine/schema/src/main/java/org/apache/cloudstack/{br/BRPolicyVO.java => backup/BackupPolicyVO.java} (78%) rename engine/schema/src/main/java/org/apache/cloudstack/{br/dao/BRPoliciesDao.java => backup/dao/BackupPolicyDao.java} (75%) rename engine/schema/src/main/java/org/apache/cloudstack/{br/dao/BRPoliciesDaoImpl.java => backup/dao/BackupPolicyDaoImpl.java} (55%) delete mode 100644 engine/schema/src/main/java/org/apache/cloudstack/br/BRProviderDetailVO.java delete mode 100644 engine/schema/src/main/java/org/apache/cloudstack/br/BRProviderVO.java delete mode 100644 engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDaoImpl.java delete mode 100644 engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDetailsDao.java delete mode 100644 engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDetailsDaoImpl.java delete mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRPolicy.java delete mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRPolicyService.java delete mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRProvider.java delete mode 100644 framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRProviderService.java rename framework/{backup-and-recovery => backup}/pom.xml (94%) create mode 100644 framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupPolicy.java create mode 100644 framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupProvider.java create mode 100644 framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupService.java delete mode 100644 plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/br/DummyBRProvider.java rename plugins/{backup-and-recovery => backup}/dummy/pom.xml (87%) create mode 100644 plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java rename plugins/{backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery => backup/dummy/src/main/resources/META-INF/cloudstack/dummy-backup}/module.properties (93%) rename plugins/{backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/spring-dummy-backup-recovery-context.xml => backup/dummy/src/main/resources/META-INF/cloudstack/dummy-backup/spring-backup-dummy-context.xml} (92%) create mode 100644 plugins/backup/veeam/pom.xml create mode 100644 plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java create mode 100644 plugins/backup/veeam/src/main/resources/META-INF/cloudstack/veeam/module.properties create mode 100644 plugins/backup/veeam/src/main/resources/META-INF/cloudstack/veeam/spring-backup-veeam-context.xml create mode 100644 server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java delete mode 100644 server/src/main/java/org/apache/cloudstack/br/BRManagerImpl.java diff --git a/api/pom.xml b/api/pom.xml index 2c7c8d0e017..6b9747646a2 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -58,7 +58,7 @@ org.apache.cloudstack - cloud-framework-backup-and-recovery + cloud-framework-backup ${project.version} 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 478067cb8a8..504b2149837 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java @@ -719,10 +719,6 @@ public class ApiConstants { public static final String LAST_ANNOTATED = "lastannotated"; public static final String LDAP_DOMAIN = "ldapdomain"; - // Backup and Recovery - public static final String BR_PROVIDER_ID = "providerid"; - public static final String BR_POLICY_ID = "policyid"; - public enum HostDetails { all, capacity, events, stats, min; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/AssignBRPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/AssignBRPolicyCmd.java deleted file mode 100644 index b6be9bc63df..00000000000 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/AssignBRPolicyCmd.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.cloudstack.api.command.admin.br.policy; - -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.br.BRManager; -import org.apache.cloudstack.br.BRProviderDriver; - -import javax.inject.Inject; - -@APICommand(name = AssignBRPolicyCmd.APINAME, - description = "Assigns a VM to an existing backup policy", - responseObject = SuccessResponse.class, since = "4.12.0") -public class AssignBRPolicyCmd extends BaseCmd { - - public static final String APINAME = "assignBRPolicy"; - - @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, - type = CommandType.UUID, - entityType = UserVmResponse.class, - required = true, - description = "id of the VM to be moved") - private String virtualMachineId; - - @Parameter(name = ApiConstants.BR_POLICY_ID, - type = CommandType.STRING, - required = true, - description = "Backup Recovery Provider ID") - private String policyId; - - public String getVirtualMachineId() { - return virtualMachineId; - } - - public String getPolicyId() { - return policyId; - } - - @Inject - BRManager brManager; - - @Override - public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { - try { - BRProviderDriver provider = brManager.getBRProviderFromPolicy(getPolicyId()); - boolean result = provider.assignVMToBackupPolicy(getPolicyId(), getVirtualMachineId()); - 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) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); - } - } - - @Override - public String getCommandName() { - return AssignBRPolicyCmd.APINAME + RESPONSE_SUFFIX; - } - - @Override - public long getEntityOwnerId() { - return CallContext.current().getCallingAccount().getId(); - } -} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/ListBRPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/ListBRPoliciesCmd.java deleted file mode 100644 index df3b6b39b74..00000000000 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/ListBRPoliciesCmd.java +++ /dev/null @@ -1,86 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package org.apache.cloudstack.api.command.admin.br.policy; - -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.BaseListCmd; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.response.ListResponse; -import org.apache.cloudstack.br.BRManager; -import org.apache.cloudstack.api.response.BRPolicyResponse; -import org.apache.cloudstack.framework.br.BRPolicy; -import org.apache.commons.collections.CollectionUtils; - -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; - -@APICommand(name = ListBRPoliciesCmd.APINAME, - description = "Lists mapped Backup policies", - responseObject = BRPolicyResponse.class, since = "4.12.0", - authorized = {RoleType.Admin}) -public class ListBRPoliciesCmd extends BaseListCmd { - - public static final String APINAME = "listBRPolicies"; - - @Parameter(name = ApiConstants.BR_PROVIDER_ID, - type = CommandType.STRING, - required = true, - description = "Backup Recovery Provider ID") - private String providerId; - - public String getProviderId() { - return providerId; - } - - @Inject - BRManager brManager; - - @Override - public void execute() throws ServerApiException, ConcurrentOperationException { - try { - ListResponse response = new ListResponse(); - List responses = new ArrayList<>(); - List policies = brManager.listBRPolicies(providerId); - if (CollectionUtils.isNotEmpty(policies)) { - for (BRPolicy policy : policies) { - responses.add(brManager.createBackupPolicyResponse(policy)); - } - } - response.setResponses(responses, responses.size()); - response.setObjectName("brpolicies"); - 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() + RESPONSE_SUFFIX; - } - -} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/AddBRProviderCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/AddBRProviderCmd.java deleted file mode 100644 index 3823b49bc28..00000000000 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/AddBRProviderCmd.java +++ /dev/null @@ -1,118 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package org.apache.cloudstack.api.command.admin.br.provider; - -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 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.br.BRManager; -import org.apache.cloudstack.context.CallContext; -import org.apache.cloudstack.api.response.BRProviderResponse; -import org.apache.cloudstack.framework.br.BRProvider; -import org.apache.log4j.Logger; - -import javax.inject.Inject; - -@APICommand(name = AddBRProviderCmd.APINAME, - description = "Adds a Backup and Recovery provider on a zone", - responseObject = BRProviderResponse.class, since = "4.12.0", - authorized = {RoleType.Admin}) -public class AddBRProviderCmd extends BaseCmd { - - public static final String APINAME = "addBRProvider"; - - private static final Logger s_logger = Logger.getLogger(AddBRProviderCmd.class); - - @Inject - BRManager brManager; - - @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 { - BRProvider providerVO = brManager.addBRProvider(name, url, username, password, zoneId, provider); - if (providerVO != null) { - BRProviderResponse response = brManager.createBRProviderResponse(providerVO); - response.setObjectName("brprovider"); - response.setResponseName(getCommandName()); - setResponseObject(response); - } else { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add a Backup and Recovery Provider"); - } - } - - @Override - public String getCommandName() { - return APINAME.toLowerCase() + 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/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/ListBRProvidersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/ListBRProvidersCmd.java deleted file mode 100644 index 53b5837702b..00000000000 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/ListBRProvidersCmd.java +++ /dev/null @@ -1,78 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package org.apache.cloudstack.api.command.admin.br.provider; - -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.BaseListCmd; -import org.apache.cloudstack.api.ApiErrorCode; -import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.response.ListResponse; -import org.apache.cloudstack.br.BRManager; -import org.apache.cloudstack.api.response.BRProviderResponse; -import org.apache.cloudstack.framework.br.BRProvider; -import org.apache.commons.collections.CollectionUtils; - -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; - -@APICommand(name = ListBRProvidersCmd.APINAME, - description = "Lists Backup and Recovery providers", - responseObject = BRProviderResponse.class, since = "4.12.0", - authorized = {RoleType.Admin}) -public class ListBRProvidersCmd extends BaseListCmd { - - public static final String APINAME = "listBRProviders"; - - @Inject - BRManager brManager; - - @Override - public void execute() throws ServerApiException, ConcurrentOperationException { - try { - List providers = brManager.listBRProviders(); - ListResponse response = new ListResponse(); - List providersResponse = new ArrayList(); - - if (CollectionUtils.isNotEmpty(providers)) { - for (BRProvider providerVO : providers) { - BRProviderResponse providerResponse = brManager.createBRProviderResponse(providerVO); - providersResponse.add(providerResponse); - } - } - - response.setResponses(providersResponse, providersResponse.size()); - response.setObjectName("brproviders"); - 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() + RESPONSE_SUFFIX; - } -} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/DeleteBRProviderCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/AssignBackupPolicyCmd.java similarity index 69% rename from api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/DeleteBRProviderCmd.java rename to api/src/main/java/org/apache/cloudstack/api/command/user/backup/AssignBackupPolicyCmd.java index 57c6e3bbd3e..e1ec19b5add 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/DeleteBRProviderCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/AssignBackupPolicyCmd.java @@ -14,71 +14,77 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. - -package org.apache.cloudstack.api.command.admin.br.provider; - -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.br.BRManager; +package org.apache.cloudstack.api.command.user.backup; import javax.inject.Inject; -@APICommand(name = DeleteBRProviderCmd.APINAME, - description = "Deletes a Backup and Recovery provider", - responseObject = SuccessResponse.class, since = "4.12.0", - authorized = {RoleType.Admin}) -public class DeleteBRProviderCmd extends BaseCmd { +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.backup.BackupManager; +import org.apache.cloudstack.context.CallContext; - public static final String APINAME = "deleteBRProvider"; +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; - @Inject - BRManager brManager; +@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.BR_PROVIDER_ID, + @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, + type = CommandType.UUID, + entityType = UserVmResponse.class, + required = true, + description = "id of the VM to be moved") + private String virtualMachineId; + + @Parameter(name = ApiConstants.POLICY_ID, type = CommandType.STRING, required = true, description = "Backup Recovery Provider ID") - private String providerId; + private String policyId; - public String getProviderId() { - return providerId; + public String getVirtualMachineId() { + return virtualMachineId; } + public String getPolicyId() { + return policyId; + } + + @Inject + BackupManager backupManager; + @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { try { - boolean result = brManager.deleteBRProvider(providerId); + ; + boolean result = backupManager.assignVMToBackupPolicy(); 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"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign VM to backup policy"); } - } catch (InvalidParameterValueException e) { + } catch (Exception 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() + RESPONSE_SUFFIX; + return AssignBackupPolicyCmd.APINAME + RESPONSE_SUFFIX; } @Override diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupCmd.java new file mode 100644 index 00000000000..8f2b651c70c --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupCmd.java @@ -0,0 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.backup; + +public class CreateBackupCmd { +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/AddBRPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupPolicyCmd.java similarity index 76% rename from api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/AddBRPolicyCmd.java rename to api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupPolicyCmd.java index 4dc16fa47b3..2f1ddacd531 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/policy/AddBRPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/CreateBackupPolicyCmd.java @@ -14,8 +14,21 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. +package org.apache.cloudstack.api.command.user.backup; -package org.apache.cloudstack.api.command.admin.br.policy; +import javax.inject.Inject; + +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.api.response.BackupPolicyResponse; +import org.apache.cloudstack.backup.BackupManager; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.backup.BackupPolicy; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -24,41 +37,27 @@ import com.cloud.exception.NetworkRuleConflictException; 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.br.BRManager; -import org.apache.cloudstack.api.response.BRPolicyResponse; -import org.apache.cloudstack.framework.br.BRPolicy; -import javax.inject.Inject; - -@APICommand(name = AddBRPolicyCmd.APINAME, - description = "Adds a Backup policy", - responseObject = BRPolicyResponse.class, since = "4.12.0", +@APICommand(name = CreateBackupPolicyCmd.APINAME, + description = "Creates a backup policy", + responseObject = BackupPolicyResponse.class, since = "4.12.0", authorized = {RoleType.Admin}) -public class AddBRPolicyCmd extends BaseCmd { - - public static final String APINAME = "addBRPolicy"; +public class CreateBackupPolicyCmd extends BaseCmd { + public static final String APINAME = "createBackupPolicy"; @Inject - BRManager brManager; + BackupManager backupManager; @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the policy") private String policyName; - @Parameter(name = ApiConstants.BR_POLICY_ID, + @Parameter(name = ApiConstants.POLICY_ID, type = CommandType.STRING, required = true, description = "Backup Recovery Provider ID") private String policyId; - @Parameter(name = ApiConstants.BR_PROVIDER_ID, + @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true, description = "Backup Recovery Provider ID") @@ -79,10 +78,13 @@ public class AddBRPolicyCmd extends BaseCmd { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { try { - BRPolicy policy = brManager.addBRPolicy(policyId, policyName, providerId); + BackupPolicy policy = backupManager.addBackupPolicy(policyId, policyName, providerId); if (policy != null) { - BRPolicyResponse response = brManager.createBackupPolicyResponse(policy); - response.setObjectName("brpolicy"); + BackupPolicyResponse response = new BackupPolicyResponse(); + response.setId(policy.getUuid()); + response.setPolicyId(policy.getPolicyUuid()); + response.setName(policy.getName()); + response.setObjectName("policy"); response.setResponseName(getCommandName()); setResponseObject(response); } else { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupCmd.java new file mode 100644 index 00000000000..eb8558534e0 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupCmd.java @@ -0,0 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.backup; + +public class DeleteBackupCmd { +} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRService.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupPolicyCmd.java similarity index 83% rename from framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRService.java rename to api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupPolicyCmd.java index 79cb3f9ec0a..66d8d2fc7ed 100644 --- a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRService.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/DeleteBackupPolicyCmd.java @@ -15,11 +15,7 @@ // specific language governing permissions and limitations // under the License. -package org.apache.cloudstack.framework.br; - -/** - * Backup and Recovery Services - */ -public interface BRService extends BRProviderService, BRPolicyService { +package org.apache.cloudstack.api.command.user.backup; +public class DeleteBackupPolicyCmd { } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/ListBRProviderPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupPoliciesCmd.java similarity index 69% rename from api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/ListBRProviderPoliciesCmd.java rename to api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupPoliciesCmd.java index 2abf678d9ba..a10ed5baf4b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/br/provider/ListBRProviderPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupPoliciesCmd.java @@ -14,13 +14,13 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. +package org.apache.cloudstack.api.command.user.backup; -package org.apache.cloudstack.api.command.admin.br.provider; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InvalidParameterValueException; -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; @@ -28,28 +28,28 @@ import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BackupPolicyResponse; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.cloudstack.br.BRManager; -import org.apache.cloudstack.br.BRProviderDriver; -import org.apache.cloudstack.api.response.BRPolicyResponse; -import org.apache.cloudstack.framework.br.BRPolicy; +import org.apache.cloudstack.backup.BackupManager; +import org.apache.cloudstack.framework.backup.BackupPolicy; -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.utils.exception.CloudRuntimeException; -@APICommand(name = ListBRProviderPoliciesCmd.APINAME, - description = "Lists Backup policies existing on the Backup and Recovery provider side", - responseObject = BRPolicyResponse.class, since = "4.12.0", +@APICommand(name = ListBackupPoliciesCmd.APINAME, + description = "Lists backup policies existing on the Backup and Recovery provider side", + responseObject = BackupPolicyResponse.class, since = "4.12.0", authorized = {RoleType.Admin}) -public class ListBRProviderPoliciesCmd extends BaseListCmd { +public class ListBackupPoliciesCmd extends BaseListCmd { - public static final String APINAME = "listBRProviderPolicies"; + public static final String APINAME = "listBackupPolicies"; @Inject - BRManager brManager; + BackupManager backupManager; - @Parameter(name = ApiConstants.BR_PROVIDER_ID, + @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true, description = "Backup Recovery Provider ID") @@ -61,19 +61,18 @@ public class ListBRProviderPoliciesCmd extends BaseListCmd { @Override public void execute() throws ResourceUnavailableException, ServerApiException, ConcurrentOperationException { - List responses = new ArrayList<>(); - ListResponse response = new ListResponse(); + List responses = new ArrayList<>(); + ListResponse response = new ListResponse(); try { - BRProviderDriver provider = brManager.getBRProviderFromProvider(providerId); - List policies = provider.listBackupPolicies(brManager.getProviderId(providerId)); + List policies = backupManager.listBackupPolicies(); if (policies == null) { throw new CloudRuntimeException("Error while retrieving backup provider policies"); } - for (BRPolicy policy : policies) { - responses.add(brManager.createBackupPolicyResponse(policy)); + for (BackupPolicy policy : policies) { + responses.add(backupManager.createBackupPolicyResponse(policy)); } response.setResponses(responses, responses.size()); - response.setObjectName("brproviderpolicies"); + response.setObjectName("policy"); response.setResponseName(getCommandName()); setResponseObject(response); } catch (InvalidParameterValueException e) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupProvidersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupProvidersCmd.java new file mode 100644 index 00000000000..2832a39b2a5 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupProvidersCmd.java @@ -0,0 +1,99 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.backup; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +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.response.BackupProviderResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.backup.BackupManager; +import org.apache.cloudstack.framework.backup.BackupProvider; + +import com.cloud.user.Account; + +@APICommand(name = ListBackupProvidersCmd.APINAME, + description = "Lists Backup and Recovery providers", + responseObject = BackupProviderResponse.class, since = "4.12.0", + authorized = {RoleType.Admin}) +public class ListBackupProvidersCmd extends BaseListCmd { + public static final String APINAME = "listBackupProviders"; + + @Inject + private BackupManager backupManager; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "List CA service provider by name") + private String name; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getName() { + return name; + } + + @Override + public String getCommandName() { + return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + private void setupResponse(final List providers) { + final ListResponse response = new ListResponse<>(); + final List responses = new ArrayList<>(); + for (final BackupProvider provider : providers) { + if (provider == null || (getName() != null && !provider.getName().equals(getName()))) { + continue; + } + final BackupProviderResponse backupProviderResponse = new BackupProviderResponse(); + backupProviderResponse.setName(provider.getName()); + backupProviderResponse.setDescription(provider.getDescription()); + backupProviderResponse.setObjectName("provider"); + responses.add(backupProviderResponse); + } + response.setResponses(responses); + response.setResponseName(getCommandName()); + setResponseObject(response); + } + + @Override + public void execute() { + List providers = backupManager.listBackupProviders(); + setupResponse(providers); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDao.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java similarity index 70% rename from engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDao.java rename to api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java index 6e339585e07..9dd89dd5ccf 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDao.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java @@ -14,15 +14,8 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package org.apache.cloudstack.br.dao; -import com.cloud.utils.db.GenericDao; -import org.apache.cloudstack.br.BRProviderVO; +package org.apache.cloudstack.api.command.user.backup; -import java.util.List; - -public interface BRProviderDao extends GenericDao { - - List listByZone(long zoneId); - List listByZoneAndProvider(long zoneId, String provider); +public class ListBackupsCmd { } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/RestoreBackupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/RestoreBackupCmd.java new file mode 100644 index 00000000000..1ae8a36224f --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/RestoreBackupCmd.java @@ -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. + +package org.apache.cloudstack.api.command.user.backup; + +public class RestoreBackupCmd { +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/BRPolicyResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/BackupPolicyResponse.java similarity index 89% rename from api/src/main/java/org/apache/cloudstack/api/response/BRPolicyResponse.java rename to api/src/main/java/org/apache/cloudstack/api/response/BackupPolicyResponse.java index 8ae8e9042e9..3c2e7509b67 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/BRPolicyResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/BackupPolicyResponse.java @@ -14,18 +14,18 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. - package org.apache.cloudstack.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.br.BRPolicy; +import org.apache.cloudstack.framework.backup.BackupPolicy; -@EntityReference(value = BRPolicy.class) -public class BRPolicyResponse extends BaseResponse { +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +@EntityReference(value = BackupPolicy.class) +public class BackupPolicyResponse extends BaseResponse { @SerializedName(ApiConstants.ID) @Param(description = "internal id of the backup policy") @@ -39,11 +39,11 @@ public class BRPolicyResponse extends BaseResponse { @Param(description = "internal name for the backup policy") private String name; - @SerializedName(ApiConstants.BR_POLICY_ID) + @SerializedName(ApiConstants.POLICY_ID) @Param(description = "policy id on the provider side") private String policyId; - @SerializedName(ApiConstants.BR_PROVIDER_ID) + @SerializedName(ApiConstants.PROVIDER) @Param(description = "id of the backup and Recovery provider") private String providerId; diff --git a/api/src/main/java/org/apache/cloudstack/api/response/BRProviderResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/BackupProviderResponse.java similarity index 54% rename from api/src/main/java/org/apache/cloudstack/api/response/BRProviderResponse.java rename to api/src/main/java/org/apache/cloudstack/api/response/BackupProviderResponse.java index 33d263ee20f..0564b3dea79 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/BRProviderResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/BackupProviderResponse.java @@ -17,53 +17,37 @@ package org.apache.cloudstack.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.br.BRProvider; +import org.apache.cloudstack.framework.backup.BackupProvider; -@EntityReference(BRProvider.class) -public class BRProviderResponse extends BaseResponse { - - @SerializedName(ApiConstants.BR_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; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +@EntityReference(BackupProvider.class) +public class BackupProviderResponse extends BaseResponse { @SerializedName(ApiConstants.NAME) - @Param(description = "internal name for the Backup and Recovery provider") + @Param(description = "the CA service provider name") private String name; - @SerializedName(ApiConstants.ZONE_ID) - @Param(description = "id of the zone") - private String zoneId; + @SerializedName(ApiConstants.DESCRIPTION) + @Param(description = "the description of the CA service provider") + private String description; - @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 String getName() { + return name; } public void setName(String name) { this.name = name; } - public void setZoneId(String zoneId) { - this.zoneId = zoneId; + public String getDescription() { + return description; } - public void setHostId(String hostId) { - this.hostId = hostId; + public void setDescription(String description) { + this.description = description; } } diff --git a/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java b/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java new file mode 100644 index 00000000000..9997cb9ede2 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/backup/BackupManager.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.backup; + +import java.util.List; + +import org.apache.cloudstack.api.response.BackupPolicyResponse; +import org.apache.cloudstack.framework.backup.BackupPolicy; +import org.apache.cloudstack.framework.backup.BackupService; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; + +import com.cloud.utils.component.Manager; +import com.cloud.utils.component.PluggableService; + +/** + * Backup and Recover Manager Interface + */ +public interface BackupManager extends BackupService, Configurable, PluggableService, Manager { + + ConfigKey BackupFrameworkEnabled = new ConfigKey<>("Advanced", Boolean.class, + "backup.framework.enabled", + "false", + "Is backup and recovery framework enabled.", true, ConfigKey.Scope.Zone); + + ConfigKey BackupProviderPlugin = new ConfigKey<>("Advanced", String.class, + "backup.framework.provider.plugin", + "", + "The backup and recovery provider plugin.", true, ConfigKey.Scope.Zone); + + + /** + * Generate a response from the Backup Policy VO + */ + BackupPolicyResponse createBackupPolicyResponse(BackupPolicy policyVO); + + /** + * Add a new Backup and Recovery policy + */ + BackupPolicy addBackupPolicy(String policyId, String policyName, String providerId); + + boolean assignVMToBackupPolicy(); + + List listBackupPolicies(); +} diff --git a/api/src/main/java/org/apache/cloudstack/br/BRProviderDriver.java b/api/src/main/java/org/apache/cloudstack/backup/BackupProviderDriver.java similarity index 88% rename from api/src/main/java/org/apache/cloudstack/br/BRProviderDriver.java rename to api/src/main/java/org/apache/cloudstack/backup/BackupProviderDriver.java index 65807f5779d..4f5916d40e2 100644 --- a/api/src/main/java/org/apache/cloudstack/br/BRProviderDriver.java +++ b/api/src/main/java/org/apache/cloudstack/backup/BackupProviderDriver.java @@ -15,17 +15,18 @@ // specific language governing permissions and limitations // under the License. -package org.apache.cloudstack.br; - -import com.cloud.utils.component.Adapter; -import org.apache.cloudstack.framework.br.BRPolicy; +package org.apache.cloudstack.backup; import java.util.List; +import org.apache.cloudstack.framework.backup.BackupPolicy; + +import com.cloud.utils.component.Adapter; + /** * Backup and Recovery Provider */ -public interface BRProviderDriver extends Adapter { +public interface BackupProviderDriver extends Adapter { /** * Register Backup and Recovery Provider @@ -40,7 +41,7 @@ public interface BRProviderDriver extends Adapter { /** * List existing Backup Policies on the provider */ - List listBackupPolicies(long providerId); + List listBackupPolicies(long providerId); /** * Assign a VM to an existing backup policy diff --git a/api/src/main/java/org/apache/cloudstack/br/BRManager.java b/api/src/main/java/org/apache/cloudstack/br/BRManager.java deleted file mode 100644 index d114ce153a3..00000000000 --- a/api/src/main/java/org/apache/cloudstack/br/BRManager.java +++ /dev/null @@ -1,58 +0,0 @@ -// 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.br; - -import com.cloud.utils.component.Manager; -import com.cloud.utils.component.PluggableService; -import org.apache.cloudstack.api.response.BRPolicyResponse; -import org.apache.cloudstack.api.response.BRProviderResponse; -import org.apache.cloudstack.framework.br.BRPolicy; -import org.apache.cloudstack.framework.br.BRProvider; -import org.apache.cloudstack.framework.br.BRService; -import org.apache.cloudstack.framework.config.Configurable; - -/** - * Backup and Recover Manager Interface - */ -public interface BRManager extends BRService, Configurable, PluggableService, Manager { - - /** - * Get the Backup and Recovery Provider for the policy id, null if not registered - */ - BRProviderDriver getBRProviderFromPolicy(String policyId); - - /** - * Get the Backup and Recovery Provider for the provider id, null if not registered - */ - BRProviderDriver getBRProviderFromProvider(String providerId); - - /** - * Generate a response from the Backup and Recovery Provider VO - */ - BRProviderResponse createBRProviderResponse(BRProvider backupRecoveryProviderVO); - - /** - * Generate a response from the Backup Policy VO - */ - BRPolicyResponse createBackupPolicyResponse(BRPolicy policyVO); - - /** - * Return Backup and Recovery id from provider uuid - */ - long getProviderId(String providerId); -} diff --git a/client/pom.xml b/client/pom.xml index db2f5be1785..32844358f5c 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -475,12 +475,17 @@ org.apache.cloudstack - cloud-framework-backup-and-recovery + cloud-framework-backup ${project.version} org.apache.cloudstack - cloud-plugin-backup-and-recovery-dummy + cloud-plugin-backup-dummy + ${project.version} + + + org.apache.cloudstack + cloud-plugin-backup-veeam ${project.version} diff --git a/core/src/main/resources/META-INF/cloudstack/backup-and-recovery/module.properties b/core/src/main/resources/META-INF/cloudstack/backup/module.properties similarity index 95% rename from core/src/main/resources/META-INF/cloudstack/backup-and-recovery/module.properties rename to core/src/main/resources/META-INF/cloudstack/backup/module.properties index 88aa812add7..b85b65ceeea 100644 --- a/core/src/main/resources/META-INF/cloudstack/backup-and-recovery/module.properties +++ b/core/src/main/resources/META-INF/cloudstack/backup/module.properties @@ -17,5 +17,5 @@ # under the License. # -name=backup-and-recovery -parent=backend \ No newline at end of file +name=backup +parent=backend diff --git a/core/src/main/resources/META-INF/cloudstack/backup-and-recovery/spring-core-lifecycle-backup-and-recovery-context-inheritable.xml b/core/src/main/resources/META-INF/cloudstack/backup/spring-core-lifecycle-backup-context-inheritable.xml similarity index 91% rename from core/src/main/resources/META-INF/cloudstack/backup-and-recovery/spring-core-lifecycle-backup-and-recovery-context-inheritable.xml rename to core/src/main/resources/META-INF/cloudstack/backup/spring-core-lifecycle-backup-context-inheritable.xml index 4af97cb0ea3..d9abd684564 100644 --- a/core/src/main/resources/META-INF/cloudstack/backup-and-recovery/spring-core-lifecycle-backup-and-recovery-context-inheritable.xml +++ b/core/src/main/resources/META-INF/cloudstack/backup/spring-core-lifecycle-backup-context-inheritable.xml @@ -25,8 +25,8 @@ > - - + + - \ No newline at end of file + 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 186f37fe13c..007def7d8de 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,7 +323,7 @@ class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry"> - diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/BRPolicyTO.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupPolicyTO.java similarity index 76% rename from engine/schema/src/main/java/org/apache/cloudstack/br/BRPolicyTO.java rename to engine/schema/src/main/java/org/apache/cloudstack/backup/BackupPolicyTO.java index cefaceb5ae0..a1e729d8cb7 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/BRPolicyTO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupPolicyTO.java @@ -17,24 +17,22 @@ * under the License. */ -package org.apache.cloudstack.br; +package org.apache.cloudstack.backup; -import org.apache.cloudstack.framework.br.BRPolicy; +import org.apache.cloudstack.framework.backup.BackupPolicy; -public class BRPolicyTO implements BRPolicy { +public class BackupPolicyTO implements BackupPolicy { private long id; private String uuid; private String name; private String policyUuid; - private long providerId; - public BRPolicyTO(final long id, final String uuid, final String name, final String policyUuid, final long providerId) { + public BackupPolicyTO(final long id, final String uuid, final String name, final String policyUuid) { this.name = name; this.uuid = uuid; this.id = id; this.policyUuid = policyUuid; - this.providerId = providerId; } @Override @@ -46,11 +44,6 @@ public class BRPolicyTO implements BRPolicy { return name; } - @Override - public long getProviderId() { - return providerId; - } - @Override public String getUuid() { return uuid; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/BRPolicyVO.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupPolicyVO.java similarity index 78% rename from engine/schema/src/main/java/org/apache/cloudstack/br/BRPolicyVO.java rename to engine/schema/src/main/java/org/apache/cloudstack/backup/BackupPolicyVO.java index ab2fa2f551d..d8fb433072d 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/BRPolicyVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupPolicyVO.java @@ -15,9 +15,9 @@ // specific language governing permissions and limitations // under the License. -package org.apache.cloudstack.br; +package org.apache.cloudstack.backup; -import org.apache.cloudstack.framework.br.BRPolicy; +import java.util.UUID; import javax.persistence.Column; import javax.persistence.Entity; @@ -25,19 +25,19 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; -import java.util.UUID; + +import org.apache.cloudstack.framework.backup.BackupPolicy; @Entity -@Table(name = "br_policies") -public class BRPolicyVO implements BRPolicy { +@Table(name = "backup_policy") +public class BackupPolicyVO implements BackupPolicy { - public BRPolicyVO() { + public BackupPolicyVO() { this.uuid = UUID.randomUUID().toString(); } - public BRPolicyVO(final long providerId, final String name, final String policyUuid) { + public BackupPolicyVO(final String name, final String policyUuid) { this(); - this.providerId = providerId; this.name = name; this.policyUuid = policyUuid; } @@ -49,9 +49,6 @@ public class BRPolicyVO implements BRPolicy { @Column(name = "uuid") private String uuid; - @Column(name = "provider_id") - private long providerId; - @Column(name = "name") private String name; @@ -89,12 +86,4 @@ public class BRPolicyVO implements BRPolicy { public void setPolicyUuid(String policyUuid) { this.policyUuid = policyUuid; } - - public long getProviderId() { - return providerId; - } - - public void setProviderId(long providerId) { - this.providerId = providerId; - } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRPoliciesDao.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupPolicyDao.java similarity index 75% rename from engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRPoliciesDao.java rename to engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupPolicyDao.java index cf3b06d3cb1..f7981e6c7b2 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRPoliciesDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupPolicyDao.java @@ -15,15 +15,12 @@ // specific language governing permissions and limitations // under the License. -package org.apache.cloudstack.br.dao; +package org.apache.cloudstack.backup.dao; + +import org.apache.cloudstack.backup.BackupPolicyVO; import com.cloud.utils.db.GenericDao; -import org.apache.cloudstack.br.BRPolicyVO; -import java.util.List; +public interface BackupPolicyDao extends GenericDao { -public interface BRPoliciesDao extends GenericDao { - - List listByProvider(long providerId); - void removeByProvider(long providerId); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRPoliciesDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupPolicyDaoImpl.java similarity index 55% rename from engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRPoliciesDaoImpl.java rename to engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupPolicyDaoImpl.java index 03b310f002d..54f20f82df9 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRPoliciesDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupPolicyDaoImpl.java @@ -15,45 +15,27 @@ // specific language governing permissions and limitations // under the License. -package org.apache.cloudstack.br.dao; +package org.apache.cloudstack.backup.dao; + +import javax.annotation.PostConstruct; + +import org.apache.cloudstack.backup.BackupPolicyVO; +import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import org.apache.cloudstack.br.BRPolicyVO; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.util.List; @Component -public class BRPoliciesDaoImpl extends GenericDaoBase implements BRPoliciesDao { +public class BackupPolicyDaoImpl extends GenericDaoBase implements BackupPolicyDao { - protected SearchBuilder backupPoliciesSearch; + protected SearchBuilder backupPoliciesSearch; - public BRPoliciesDaoImpl() { + public BackupPolicyDaoImpl() { } @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); - } - - @Override - public void removeByProvider(long providerId) { - SearchCriteria sc = backupPoliciesSearch.create(); - sc.setParameters("provider", providerId); - expunge(sc); - } - - } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/BRProviderDetailVO.java b/engine/schema/src/main/java/org/apache/cloudstack/br/BRProviderDetailVO.java deleted file mode 100644 index 662673cab52..00000000000 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/BRProviderDetailVO.java +++ /dev/null @@ -1,81 +0,0 @@ -// 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.br; - -import com.cloud.utils.db.Encrypt; -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; - -@Entity -@Table(name = "br_provider_details") -public class BRProviderDetailVO implements InternalIdentity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private long id; - - @Column(name = "provider_id") - private long providerId; - - @Column(name = "name") - private String name; - - @Encrypt - @Column(name = "value") - private String value; - - public BRProviderDetailVO() { - } - - public BRProviderDetailVO(long providerId, String name, String value) { - this.providerId = providerId; - this.name = name; - this.value = value; - } - - public long getProviderId() { - return providerId; - } - - public long getResourceId() { - return providerId; - } - - public String getName() { - return name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - @Override - public long getId() { - return id; - } -} \ No newline at end of file diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/BRProviderVO.java b/engine/schema/src/main/java/org/apache/cloudstack/br/BRProviderVO.java deleted file mode 100644 index 9ac1fc905dc..00000000000 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/BRProviderVO.java +++ /dev/null @@ -1,112 +0,0 @@ -// 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.br; - -import org.apache.cloudstack.framework.br.BRProvider; - -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 = "br_provider") -public class BRProviderVO implements BRProvider { - - public BRProviderVO() { - this.uuid = UUID.randomUUID().toString(); - } - - public BRProviderVO(final String name, final long zoneId, final String url, final String provider) { - this(); - this.name = name; - this.zoneId = zoneId; - this.provider = provider; - this.url = url; - } - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - @Column(name = "uuid") - private String uuid; - - @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 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/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDaoImpl.java deleted file mode 100644 index abfe34dbc58..00000000000 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDaoImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -// 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.br.dao; - -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import org.apache.cloudstack.br.BRProviderVO; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.util.List; - -@Component -public class BRProviderDaoImpl extends GenericDaoBase implements BRProviderDao { - - protected SearchBuilder brProviderSearch; - - public BRProviderDaoImpl() { - } - - @PostConstruct - protected void init() { - brProviderSearch = createSearchBuilder(); - brProviderSearch.and("zoneid", brProviderSearch.entity().getZoneId(), SearchCriteria.Op.EQ); - brProviderSearch.and("provider", brProviderSearch.entity().getProviderName(), SearchCriteria.Op.EQ); - brProviderSearch.done(); - } - - @Override - public List listByZone(long zoneId) { - SearchCriteria sc = brProviderSearch.create(); - sc.setParameters("zoneid", zoneId); - return listBy(sc); - } - - @Override - public List listByZoneAndProvider(long zoneId, String provider) { - SearchCriteria sc = brProviderSearch.create(); - sc.setParameters("zoneid", zoneId); - sc.setParameters("provider", provider); - return listBy(sc); - } -} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDetailsDao.java b/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDetailsDao.java deleted file mode 100644 index 7129f52c04c..00000000000 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDetailsDao.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.apache.cloudstack.br.dao; - -import com.cloud.utils.db.GenericDao; -import org.apache.cloudstack.br.BRProviderDetailVO; - -import java.util.List; - -public interface BRProviderDetailsDao extends GenericDao { - - void addDetails(List details); - void removeDetails(long providerId); -} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDetailsDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDetailsDaoImpl.java deleted file mode 100644 index 01b9545db90..00000000000 --- a/engine/schema/src/main/java/org/apache/cloudstack/br/dao/BRProviderDetailsDaoImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -// 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.br.dao; - -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import org.apache.cloudstack.br.BRProviderDetailVO; - -import javax.annotation.PostConstruct; -import java.util.List; - -public class BRProviderDetailsDaoImpl extends GenericDaoBase implements BRProviderDetailsDao { - - protected SearchBuilder detailsSearch; - - @PostConstruct - protected void init() { - detailsSearch = createSearchBuilder(); - detailsSearch.and("provider", detailsSearch.entity().getProviderId(), SearchCriteria.Op.EQ); - detailsSearch.done(); - } - - - @Override - public void addDetails(List details) { - for (BRProviderDetailVO detail : details) { - persist(detail); - } - } - - @Override - public void removeDetails(long providerId) { - SearchCriteria sc = detailsSearch.create(); - sc.setParameters("provider", providerId); - remove(sc); - } -} diff --git a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml index 899cd07ae2e..0809aa7d7ef 100644 --- a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml +++ b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -356,7 +356,5 @@ - - - + 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 7d4af6e5615..f9b85124933 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 @@ -36,36 +36,11 @@ INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, -- Backup and Recovery -CREATE TABLE IF NOT EXISTS `cloud`.`br_provider` ( - `id` bigint unsigned NOT NULL AUTO_INCREMENT, - `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', - `provider` varchar(255) DEFAULT NULL COMMENT 'the backup and recovery provider', - PRIMARY KEY (`id`), - UNIQUE KEY `uuid` (`uuid`), - 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`.`br_provider_details` ( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `provider_id` bigint(20) unsigned NOT NULL COMMENT 'backup and recovery provider id', - `name` varchar(255) NOT NULL, - `value` varchar(255) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `uk_provider_id_name` (`provider_id`,`name`), - KEY `fk_br_provider_details__provider_id` (`provider_id`), - CONSTRAINT `fk_br_provider_details__provider_id` FOREIGN KEY (`provider_id`) REFERENCES `br_provider` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=496 DEFAULT CHARSET=utf8; - -CREATE TABLE IF NOT EXISTS `cloud`.`br_policies` ( +CREATE TABLE IF NOT EXISTS `cloud`.`backup_policy` ( `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_br_policies__provider_id` FOREIGN KEY (`provider_id`) REFERENCES `br_provider` (`id`) ON DELETE CASCADE + UNIQUE KEY `uuid` (`uuid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRPolicy.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRPolicy.java deleted file mode 100644 index f79993069e4..00000000000 --- a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRPolicy.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.br; - -public interface BRPolicy { - - long getId(); - String getUuid(); - String getPolicyUuid(); - String getName(); - long getProviderId(); -} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRPolicyService.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRPolicyService.java deleted file mode 100644 index 5812eb52527..00000000000 --- a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRPolicyService.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apache.cloudstack.framework.br; - -import java.util.List; - -/** - * Backup and Recovery Policies Services - */ -public interface BRPolicyService { - - /** - * Add a new Backup and Recovery policy - */ - BRPolicy addBRPolicy(String policyId, String policyName, String providerId); - - /** - * List Backup policies - */ - List listBRPolicies(String providerId); -} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRProvider.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRProvider.java deleted file mode 100644 index be1f8c344c1..00000000000 --- a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRProvider.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.apache.cloudstack.framework.br; - -public interface BRProvider { - long getId(); - String getUuid(); - String getName(); - String getUrl(); - long getZoneId(); - String getProviderName(); -} diff --git a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRProviderService.java b/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRProviderService.java deleted file mode 100644 index ef5c1c167ac..00000000000 --- a/framework/backup-and-recovery/src/main/java/org/apache/cloudstack/framework/br/BRProviderService.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apache.cloudstack.framework.br; - -import java.util.List; - -/** - * Backup and Recovery Provider Services - */ -public interface BRProviderService { - - /** - * Add a new Backup and Recovery provider - */ - BRProvider addBRProvider(String name, String url, String username, String password, Long zoneId, String providerName); - - /** - * List existing Backup and Recovery providers - */ - List listBRProviders(); - - /** - * Delete existing Backup and Recovery provider - */ - boolean deleteBRProvider(String providerId); -} diff --git a/framework/backup-and-recovery/pom.xml b/framework/backup/pom.xml similarity index 94% rename from framework/backup-and-recovery/pom.xml rename to framework/backup/pom.xml index 3bef73590fe..31fef4f342c 100644 --- a/framework/backup-and-recovery/pom.xml +++ b/framework/backup/pom.xml @@ -19,7 +19,7 @@ 4.0.0 - cloud-framework-backup-and-recovery + cloud-framework-backup Apache CloudStack Framework - Backup and Recovery cloudstack-framework @@ -29,4 +29,4 @@ - \ No newline at end of file + diff --git a/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupPolicy.java b/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupPolicy.java new file mode 100644 index 00000000000..53edb30f8ab --- /dev/null +++ b/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupPolicy.java @@ -0,0 +1,24 @@ +//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 +//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.backup; + +public interface BackupPolicy { + long getId(); + String getUuid(); + String getPolicyUuid(); + String getName(); +} diff --git a/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupProvider.java b/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupProvider.java new file mode 100644 index 00000000000..69f999ee427 --- /dev/null +++ b/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupProvider.java @@ -0,0 +1,32 @@ +//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 +//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.backup; + +public interface BackupProvider { + + /** + * Returns the unique name of the provider + * @return returns provider name + */ + String getName(); + + /** + * Returns description about the backup and recovery provider plugin + * @return returns description + */ + String getDescription(); +} diff --git a/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupService.java b/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupService.java new file mode 100644 index 00000000000..419fb1adb76 --- /dev/null +++ b/framework/backup/src/main/java/org/apache/cloudstack/framework/backup/BackupService.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 +//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.backup; + +import java.util.List; + +/** + * Backup and Recovery Services + */ +public interface BackupService { + /** + * Lists backup and recovery provider plugins + * @return list of providers + */ + List listBackupProviders(); + + /** + * Find backup provider by name and zone ID + * When null is provided as name, the configured provider is returned + * @param providerName + * @param zoneId + * @return backup provider + */ + BackupProvider getBackupProvider(final String providerName, final Long zoneId); +} diff --git a/framework/pom.xml b/framework/pom.xml index 709e6efbb14..6648b1ee986 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -58,6 +58,6 @@ security agent-lb direct-download - backup-and-recovery + backup diff --git a/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/br/DummyBRProvider.java b/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/br/DummyBRProvider.java deleted file mode 100644 index 696bf8b4068..00000000000 --- a/plugins/backup-and-recovery/dummy/src/main/java/org/apache/cloudstack/br/DummyBRProvider.java +++ /dev/null @@ -1,74 +0,0 @@ -// 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.br; - -import com.cloud.utils.component.AdapterBase; -import org.apache.cloudstack.framework.br.BRPolicy; -import org.apache.log4j.Logger; - -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -public class DummyBRProvider extends AdapterBase implements BRProviderDriver { - - private static final Logger s_logger = Logger.getLogger(DummyBRProvider.class); - - @Override - public boolean registerProvider(long zoneId, String name, String url, String username, String password) { - s_logger.debug("Registering Dummy Backup and Recovery provider"); - return true; - } - - @Override - public List listBackupPolicies(long providerId) { - s_logger.debug("Listing Dummy Backup policies"); - BRPolicy policy1 = new BRPolicyTO(1l, UUID.randomUUID().toString(), "Golden Policy", "aaaa-aaaa", providerId); - BRPolicy policy2 = new BRPolicyTO(1l, UUID.randomUUID().toString(), "Silver Policy", "bbbb-bbbb", providerId); - return Arrays.asList(policy1, policy2); - } - - @Override - public boolean policyExists(String policyId, String policyName) { - s_logger.debug("Checking if policy " + policyId + " " + policyName + " exists"); - return true; - } - - @Override - public boolean assignVMToBackupPolicy(String policyId, String vmId) { - s_logger.debug("Assigning VM " + vmId+ " to the policy " + policyId); - return true; - } - - @Override - public boolean unregisterProvider() { - s_logger.debug("Unregistering Dummy Backup and Recovery provider"); - return true; - } - - @Override - public void restoreVMFromBackup() { - - } - - @Override - public void restoreAndAttachVolumeToVM() { - - } - -} diff --git a/plugins/backup-and-recovery/dummy/pom.xml b/plugins/backup/dummy/pom.xml similarity index 87% rename from plugins/backup-and-recovery/dummy/pom.xml rename to plugins/backup/dummy/pom.xml index 500dc66d1b7..8505466cf40 100644 --- a/plugins/backup-and-recovery/dummy/pom.xml +++ b/plugins/backup/dummy/pom.xml @@ -18,8 +18,8 @@ --> 4.0.0 - cloud-plugin-backup-and-recovery-dummy - Apache CloudStack Plugin - Backup and Recovery Dummy Plugin + cloud-plugin-backup-dummy + Apache CloudStack Plugin - Dummy Backup and Recovery Plugin cloudstack-plugins org.apache.cloudstack @@ -29,8 +29,8 @@ org.apache.cloudstack - cloud-framework-backup-and-recovery + cloud-framework-backup ${project.version} - \ No newline at end of file + diff --git a/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java b/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java new file mode 100644 index 00000000000..ad4e04e90ca --- /dev/null +++ b/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java @@ -0,0 +1,34 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.backup; + +import org.apache.cloudstack.framework.backup.BackupProvider; + +import com.cloud.utils.component.AdapterBase; + +public class DummyBackupProvider extends AdapterBase implements BackupProvider { + + @Override + public String getName() { + return "dummy"; + } + + @Override + public String getDescription() { + return "Dummy B&R Provider"; + } +} diff --git a/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/module.properties b/plugins/backup/dummy/src/main/resources/META-INF/cloudstack/dummy-backup/module.properties similarity index 93% rename from plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/module.properties rename to plugins/backup/dummy/src/main/resources/META-INF/cloudstack/dummy-backup/module.properties index e4554a31519..5969fb29054 100644 --- a/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/module.properties +++ b/plugins/backup/dummy/src/main/resources/META-INF/cloudstack/dummy-backup/module.properties @@ -14,6 +14,5 @@ # 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 +name=dummy-backup +parent=backup 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/dummy/src/main/resources/META-INF/cloudstack/dummy-backup/spring-backup-dummy-context.xml similarity index 92% rename from plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/spring-dummy-backup-recovery-context.xml rename to plugins/backup/dummy/src/main/resources/META-INF/cloudstack/dummy-backup/spring-backup-dummy-context.xml index b591ef725ed..e154f9fe945 100644 --- a/plugins/backup-and-recovery/dummy/src/main/resources/META-INF/cloudstack/dummy-backup-recovery/spring-dummy-backup-recovery-context.xml +++ b/plugins/backup/dummy/src/main/resources/META-INF/cloudstack/dummy-backup/spring-backup-dummy-context.xml @@ -21,7 +21,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" > - - + + - \ No newline at end of file + diff --git a/plugins/backup/veeam/pom.xml b/plugins/backup/veeam/pom.xml new file mode 100644 index 00000000000..09f0880da7f --- /dev/null +++ b/plugins/backup/veeam/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + cloud-plugin-backup-veeam + Apache CloudStack Plugin - Veeam Backup and Recovery Plugin + + cloudstack-plugins + org.apache.cloudstack + 4.12.0.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-framework-backup + ${project.version} + + + diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java new file mode 100644 index 00000000000..f4f62849130 --- /dev/null +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java @@ -0,0 +1,70 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.backup; + +import org.apache.cloudstack.framework.backup.BackupProvider; +import org.apache.cloudstack.framework.backup.BackupService; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.log4j.Logger; + +import com.cloud.utils.component.AdapterBase; + +public class VeeamBackupProvider extends AdapterBase implements BackupProvider, Configurable { + private static final Logger LOG = Logger.getLogger(VeeamBackupProvider.class); + + private ConfigKey VeeamUrl = new ConfigKey<>("Advanced", String.class, + "backup.plugin.veeam.url", + "", + "The Veeam backup and recovery URL.", true, ConfigKey.Scope.Zone); + + private ConfigKey VeeamUsername = new ConfigKey<>("Advanced", String.class, + "backup.plugin.veeam.username", + "", + "The Veeam backup and recovery username.", true, ConfigKey.Scope.Zone); + + private ConfigKey VeeamPassword = new ConfigKey<>("Advanced", String.class, + "backup.plugin.veeam.password", + "", + "The Veeam backup and recovery password.", true, ConfigKey.Scope.Zone); + + + @Override + public String getConfigComponentName() { + return BackupService.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[]{ + VeeamUrl, + VeeamUsername, + VeeamPassword + }; + } + + @Override + public String getName() { + return "veeam"; + } + + @Override + public String getDescription() { + return "Veeam B&R Plugin"; + } +} diff --git a/plugins/backup/veeam/src/main/resources/META-INF/cloudstack/veeam/module.properties b/plugins/backup/veeam/src/main/resources/META-INF/cloudstack/veeam/module.properties new file mode 100644 index 00000000000..ee40b21a323 --- /dev/null +++ b/plugins/backup/veeam/src/main/resources/META-INF/cloudstack/veeam/module.properties @@ -0,0 +1,18 @@ +# 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=veeam +parent=backup diff --git a/plugins/backup/veeam/src/main/resources/META-INF/cloudstack/veeam/spring-backup-veeam-context.xml b/plugins/backup/veeam/src/main/resources/META-INF/cloudstack/veeam/spring-backup-veeam-context.xml new file mode 100644 index 00000000000..f2403cf37a4 --- /dev/null +++ b/plugins/backup/veeam/src/main/resources/META-INF/cloudstack/veeam/spring-backup-veeam-context.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/plugins/pom.xml b/plugins/pom.xml index 77b6d048f58..92dc6f6e710 100755 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -110,7 +110,8 @@ database/quota integrations/cloudian integrations/prometheus - backup-and-recovery/dummy + backup/dummy + backup/veeam diff --git a/server/pom.xml b/server/pom.xml index bf3de1f3ebf..01827fdb29d 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -146,16 +146,16 @@ cloud-engine-storage-configdrive ${project.version} + + org.apache.cloudstack + cloud-framework-backup + ${project.version} + org.opensaml opensaml ${cs.opensaml.version} - - org.apache.cloudstack - cloud-framework-backup-and-recovery - ${project.version} - diff --git a/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java b/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java new file mode 100644 index 00000000000..c5aebf33f02 --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java @@ -0,0 +1,139 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.backup; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.api.command.user.backup.CreateBackupPolicyCmd; +import org.apache.cloudstack.api.command.user.backup.ListBackupPoliciesCmd; +import org.apache.cloudstack.api.command.user.backup.ListBackupProvidersCmd; +import org.apache.cloudstack.api.response.BackupPolicyResponse; +import org.apache.cloudstack.backup.dao.BackupPolicyDao; +import org.apache.cloudstack.framework.backup.BackupPolicy; +import org.apache.cloudstack.framework.backup.BackupProvider; +import org.apache.cloudstack.framework.backup.BackupService; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.exception.CloudRuntimeException; +import com.google.common.base.Strings; + +@Component +public class BackupManagerImpl extends ManagerBase implements BackupManager { + private static final Logger LOG = Logger.getLogger(BackupManagerImpl.class); + + @Inject + BackupPolicyDao backupPolicyDao; + + @Inject + DataCenterDao dataCenterDao; + + private static Map backupProvidersMap = new HashMap<>(); + private List backupProviders; + + @Override + public BackupPolicy addBackupPolicy(String policyId, String policyName, String providerId) { + BackupProvider provider = getBackupProvider(null, null); + boolean exists = false; //provider.policyExists(policyId, policyName); + if (!exists) { + throw new CloudRuntimeException("Policy " + policyId + " does not exist on provider " + provider.getName()); + } + + BackupPolicyVO policy = new BackupPolicyVO(policyName, policyId); + return backupPolicyDao.persist(policy); + } + + @Override + public boolean assignVMToBackupPolicy() { + return false; + } + + @Override + public List listBackupPolicies() { + return null; + } + + @Override + public BackupPolicyResponse createBackupPolicyResponse(BackupPolicy policyVO) { + return null; + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + return true; + } + + public boolean isEnabled(final Long zoneId) { + return BackupFrameworkEnabled.valueIn(zoneId); + } + + @Override + public List listBackupProviders() { + return backupProviders; + } + + @Override + public BackupProvider getBackupProvider(final String providerName, final Long zoneId) { + String name = providerName; + if (Strings.isNullOrEmpty(name)) { + name = BackupProviderPlugin.valueIn(zoneId); + } + return backupProvidersMap.getOrDefault(name, null); + } + + @Override + public List> getCommands() { + final List> cmdList = new ArrayList>(); + cmdList.add(ListBackupProvidersCmd.class); + cmdList.add(ListBackupPoliciesCmd.class); + cmdList.add(CreateBackupPolicyCmd.class); + return cmdList; + } + + @Override + public String getConfigComponentName() { + return BackupService.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[]{BackupFrameworkEnabled, BackupProviderPlugin}; + } + + public void setBackupProviders(final List backupProviders) { + this.backupProviders = backupProviders; + initializeBackupProviderMap(); + } + + private void initializeBackupProviderMap() { + if (backupProviders != null && backupProviders.size() != backupProviders.size()) { + for (final BackupProvider backupProvider : backupProviders) { + backupProvidersMap.put(backupProvider.getName().toLowerCase(), backupProvider); + } + } + } +} diff --git a/server/src/main/java/org/apache/cloudstack/br/BRManagerImpl.java b/server/src/main/java/org/apache/cloudstack/br/BRManagerImpl.java deleted file mode 100644 index 3f20011e9d7..00000000000 --- a/server/src/main/java/org/apache/cloudstack/br/BRManagerImpl.java +++ /dev/null @@ -1,260 +0,0 @@ -// 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.br; - -import com.cloud.dc.DataCenterVO; -import com.cloud.dc.dao.DataCenterDao; -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.cloudstack.br.dao.BRProviderDetailsDao; -import org.apache.cloudstack.framework.br.BRPolicy; -import org.apache.cloudstack.framework.br.BRProvider; -import org.apache.cloudstack.api.command.admin.br.policy.AddBRPolicyCmd; -import org.apache.cloudstack.api.command.admin.br.provider.AddBRProviderCmd; -import org.apache.cloudstack.api.command.admin.br.provider.DeleteBRProviderCmd; -import org.apache.cloudstack.api.command.admin.br.policy.ListBRPoliciesCmd; -import org.apache.cloudstack.api.command.admin.br.provider.ListBRProviderPoliciesCmd; -import org.apache.cloudstack.api.command.admin.br.provider.ListBRProvidersCmd; -import org.apache.cloudstack.api.response.BRPolicyResponse; -import org.apache.cloudstack.api.response.BRProviderResponse; -import org.apache.cloudstack.br.dao.BRPoliciesDao; -import org.apache.cloudstack.br.dao.BRProviderDao; -import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import javax.inject.Inject; -import javax.naming.ConfigurationException; -import java.security.InvalidParameterException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.ArrayList; - -@Component -public class BRManagerImpl extends ManagerBase implements BRManager { - - @Inject - BRProviderDao brProviderDao; - @Inject - BRProviderDetailsDao brProviderDetailsDao; - @Inject - BRPoliciesDao brPoliciesDao; - @Inject - DataCenterDao dataCenterDao; - - private List brProviders = new ArrayList<>(); - private Map brProvidersMap = new HashMap<>(); - - private static final Logger s_logger = Logger.getLogger(BRManagerImpl.class); - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - super.configure(name, params); - return true; - } - - public BRProviderDriver getBRProvider(String provider) { - return brProvidersMap.getOrDefault(provider, null); - } - - public BRProviderDriver getBRProviderFromPolicy(String policyId) { - BRPolicyVO policy = brPoliciesDao.findByUuid(policyId); - BRProviderVO provider = brProviderDao.findById(policy.getProviderId()); - return getBRProvider(provider.getProviderName()); - } - - public BRProviderDriver getBRProviderFromProvider(String providerId) { - BRProviderVO provider = brProviderDao.findByUuid(providerId); - return brProvidersMap.getOrDefault(provider.getProviderName(), null); - } - - public List getBackupRecoveryProviders() { - return brProviders; - } - - public void setBackupRecoveryProviders(List backupRecoveryProviders) { - this.brProviders = backupRecoveryProviders; - } - - private void initializeDriversMap() { - if (brProvidersMap.isEmpty() && brProviders != null && brProviders.size() > 0) { - for (final BRProviderDriver driver : brProviders) { - brProvidersMap.put(driver.getName().toLowerCase(), driver); - } - s_logger.debug("Discovered Backup and Recovery providers configured in the BRManager"); - } - } - @Override - public boolean start() { - initializeDriversMap(); - return true; - } - - /* - Backup Provider provider services - */ - - List createProviderDetails(long providerId, String url, String username, String password) { - BRProviderDetailVO detail1 = new BRProviderDetailVO(providerId, "url", url); - BRProviderDetailVO detail2 = new BRProviderDetailVO(providerId, "username", username); - BRProviderDetailVO detail3 = new BRProviderDetailVO(providerId, "password", password); - return Arrays.asList(detail1, detail2, detail3); - } - - @Override - public BRProviderVO addBRProvider(String name, String url, String username, String password, Long zoneId, String providerName) { - if (!brProvidersMap.containsKey(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); - BRProviderDriver provider = brProvidersMap.get(providerName); - boolean result = provider.registerProvider(zoneId, name, url, username, password); - - if (!result) { - throw new CloudRuntimeException("Could not register backup and recovery provider " + name); - } - - try { - BRProviderVO providerVO = new BRProviderVO(name, zoneId, url, providerName); - providerVO = brProviderDao.persist(providerVO); - - brProviderDetailsDao.addDetails(createProviderDetails(providerVO.getId(), url, username, password)); - return providerVO; - } catch (Exception e) { - throw new CloudRuntimeException("Error persisting Backup and recovery provider after succesfull registration: " + e.getMessage()); - } - } - - @Override - public List listBRProviders() { - return new ArrayList(brProviderDao.listAll()); - } - - @Override - public boolean deleteBRProvider(String providerUuid) { - BRProviderVO providerVO = brProviderDao.findByUuid(providerUuid); - long providerId = providerVO.getId(); - if (providerVO == null) { - throw new InvalidParameterValueException("Could not find a Backup and Recovery provider with id: " + providerId); - } - BRProviderDriver provider = brProvidersMap.get(providerVO.getProviderName()); - boolean result = provider.unregisterProvider(); - - if (!result) { - throw new CloudRuntimeException("Unable to unregister provider: " + providerVO.getProviderName() + " id: " +providerId); - } - - clearBRPolicies(providerId); - clearBRProviderDetails(providerId); - - brProviderDao.remove(providerId); - return true; - } - - /* - Backup Provider policies services - */ - @Override - public BRPolicy addBRPolicy(String policyId, String policyName, String providerId) { - BRProviderVO providerVO = brProviderDao.findByUuid(providerId); - BRProviderDriver provider = getBRProvider(providerVO.getProviderName()); - boolean exists = provider.policyExists(policyId, policyName); - if (!exists) { - throw new CloudRuntimeException("Policy " + policyId + " does not exist on provider " + providerVO.getName()); - } - - BRPolicyVO policy = new BRPolicyVO(providerVO.getId(), policyName, policyId); - return brPoliciesDao.persist(policy); - } - - @Override - public List listBRPolicies(String providerId) { - BRProviderVO provider = brProviderDao.findByUuid(providerId); - return new ArrayList(brPoliciesDao.listByProvider(provider.getId())); - } - - /** - * Remove a Backup and Recovery Provider mapped policies - */ - private void clearBRPolicies(long providerId) { - brPoliciesDao.removeByProvider(providerId); - } - - /** - * Remove a Backup and Recovery Provider details - */ - private void clearBRProviderDetails(Long providerId) { - brProviderDetailsDao.removeDetails(providerId); - } - - @Override - public BRProviderResponse createBRProviderResponse(BRProvider vo) { - DataCenterVO dc = dataCenterDao.findById(vo.getZoneId()); - - BRProviderResponse response = new BRProviderResponse(); - response.setId(vo.getUuid()); - response.setName(vo.getName()); - response.setProviderName(vo.getProviderName()); - response.setZoneId(dc.getUuid()); - return response; - } - - @Override - public BRPolicyResponse createBackupPolicyResponse(BRPolicy policyVO) { - BRProviderVO provider = brProviderDao.findById(policyVO.getProviderId()); - - BRPolicyResponse response = new BRPolicyResponse(); - response.setId(policyVO.getUuid()); - response.setPolicyId(policyVO.getPolicyUuid()); - response.setName(policyVO.getName()); - response.setProviderId(provider.getUuid()); - return response; - } - - @Override - public long getProviderId(String providerId) { - BRProviderVO provider = brProviderDao.findByUuid(providerId); - return provider.getId(); - } - - @Override - public List> getCommands() { - final List> cmdList = new ArrayList>(); - cmdList.add(AddBRProviderCmd.class); - cmdList.add(DeleteBRProviderCmd.class); - cmdList.add(ListBRProvidersCmd.class); - cmdList.add(ListBRPoliciesCmd.class); - cmdList.add(ListBRProviderPoliciesCmd.class); - cmdList.add(AddBRPolicyCmd.class); - return cmdList; - } - - @Override - public String getConfigComponentName() { - return null; - } - - @Override - public ConfigKey[] getConfigKeys() { - return new ConfigKey[0]; - } -} diff --git a/server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml b/server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml index 3175a1baa53..7a78081ddc6 100644 --- a/server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml +++ b/server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml @@ -299,7 +299,7 @@ - - + + diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py index c52a67de58a..aa952e20922 100644 --- a/tools/apidoc/gen_toc.py +++ b/tools/apidoc/gen_toc.py @@ -191,7 +191,7 @@ known_categories = { 'listElastistorInterface': 'Misc', 'cloudian': 'Cloudian', 'Sioc' : 'Sioc', - 'BR' : 'BackupRecovery' + 'Backup' : 'Backup' }