mirror of https://github.com/apache/cloudstack.git
Big refactor and improvements
This commit is contained in:
parent
fcd39839f8
commit
a31de6cf36
|
|
@ -56,6 +56,11 @@
|
|||
<artifactId>cloud-framework-ca</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-framework-backup-and-recovery</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public interface Host extends StateObject<Status>, Identity, Partition, HAResour
|
|||
Storage(false), Routing(false), SecondaryStorage(false), SecondaryStorageCmdExecutor(false), ConsoleProxy(true), ExternalFirewall(false), ExternalLoadBalancer(
|
||||
false), ExternalVirtualSwitchSupervisor(false), PxeServer(false), BaremetalPxe(false), BaremetalDhcp(false), TrafficMonitor(false), NetScalerControlCenter(false),
|
||||
|
||||
ExternalDhcp(false), SecondaryStorageVM(true), LocalSecondaryStorage(false), L2Networking(false), BackupRecovery(true);
|
||||
ExternalDhcp(false), SecondaryStorageVM(true), LocalSecondaryStorage(false), L2Networking(false);
|
||||
boolean _virtual;
|
||||
|
||||
private Type(boolean virtual) {
|
||||
|
|
|
|||
|
|
@ -720,9 +720,8 @@ public class ApiConstants {
|
|||
public static final String LDAP_DOMAIN = "ldapdomain";
|
||||
|
||||
// Backup and Recovery
|
||||
public static final String BACKUP_PROVIDER_ID = "backupproviderid";
|
||||
public static final String BACKUP_POLICY_ID = "backuppolicyid";
|
||||
public static final String BACKUP_POLICY_NAME = "backuppolicyname";
|
||||
public static final String BR_PROVIDER_ID = "providerid";
|
||||
public static final String BR_POLICY_ID = "policyid";
|
||||
|
||||
public enum HostDetails {
|
||||
all, capacity, events, stats, min;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,26 @@
|
|||
package org.apache.cloudstack.framework.backuprecovery.api;
|
||||
// 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.InvalidParameterValueException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
|
@ -16,40 +32,37 @@ import org.apache.cloudstack.api.BaseCmd;
|
|||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
|
||||
import 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 = AddBackupRecoveryPolicyCmd.APINAME,
|
||||
@APICommand(name = AddBRPolicyCmd.APINAME,
|
||||
description = "Adds a Backup policy",
|
||||
responseObject = BackupPolicyResponse.class, since = "4.12.0",
|
||||
responseObject = BRPolicyResponse.class, since = "4.12.0",
|
||||
authorized = {RoleType.Admin})
|
||||
public class AddBackupRecoveryPolicyCmd extends BaseCmd {
|
||||
public class AddBRPolicyCmd extends BaseCmd {
|
||||
|
||||
public static final String APINAME = "addBackupRecoveryPolicy";
|
||||
public static final String APINAME = "addBRPolicy";
|
||||
|
||||
@Inject
|
||||
BackupRecoveryManager backupRecoveryManager;
|
||||
BRManager brManager;
|
||||
|
||||
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the policy")
|
||||
private String policyName;
|
||||
|
||||
@Parameter(name = ApiConstants.BACKUP_POLICY_ID,
|
||||
@Parameter(name = ApiConstants.BR_POLICY_ID,
|
||||
type = CommandType.STRING,
|
||||
entityType = BackupRecoveryProviderResponse.class,
|
||||
required = true,
|
||||
description = "Backup Recovery Provider ID")
|
||||
private String policyId;
|
||||
|
||||
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
|
||||
type = BaseCmd.CommandType.UUID,
|
||||
entityType = BackupRecoveryProviderResponse.class,
|
||||
@Parameter(name = ApiConstants.BR_PROVIDER_ID,
|
||||
type = CommandType.STRING,
|
||||
required = true,
|
||||
description = "Backup Recovery Provider ID")
|
||||
private Long providerId;
|
||||
private String providerId;
|
||||
|
||||
public String getPolicyName() {
|
||||
return policyName;
|
||||
|
|
@ -59,17 +72,17 @@ public class AddBackupRecoveryPolicyCmd extends BaseCmd {
|
|||
return policyId;
|
||||
}
|
||||
|
||||
public Long getProviderId() {
|
||||
public String getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
|
||||
try {
|
||||
BackupPolicyVO policyVO = backupRecoveryManager.addBackupPolicy(this);
|
||||
if (policyVO != null) {
|
||||
BackupPolicyResponse response = backupRecoveryManager.createBackupPolicyResponse(policyVO);
|
||||
response.setObjectName("backuppolicy");
|
||||
BRPolicy policy = brManager.addBRPolicy(policyId, policyName, providerId);
|
||||
if (policy != null) {
|
||||
BRPolicyResponse response = brManager.createBackupPolicyResponse(policy);
|
||||
response.setObjectName("brpolicy");
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
|
|
@ -79,14 +92,12 @@ public class AddBackupRecoveryPolicyCmd extends BaseCmd {
|
|||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
|
||||
} catch (CloudRuntimeException e) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
|
||||
} catch (OperationTimedoutException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
|
||||
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.api;
|
||||
package org.apache.cloudstack.api.command.admin.br.policy;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
|
|
@ -33,33 +33,32 @@ import org.apache.cloudstack.api.ServerApiException;
|
|||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import org.apache.cloudstack.br.BRManager;
|
||||
import org.apache.cloudstack.br.BRProviderDriver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@APICommand(name = AssignBackupPolicyCmd.APINAME,
|
||||
@APICommand(name = AssignBRPolicyCmd.APINAME,
|
||||
description = "Assigns a VM to an existing backup policy",
|
||||
responseObject = SuccessResponse.class, since = "4.12.0")
|
||||
public class AssignBackupPolicyCmd extends BaseCmd {
|
||||
public class AssignBRPolicyCmd extends BaseCmd {
|
||||
|
||||
public static final String APINAME = "assignBackupPolicy";
|
||||
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 Long virtualMachineId;
|
||||
private String virtualMachineId;
|
||||
|
||||
@Parameter(name = ApiConstants.BACKUP_POLICY_ID,
|
||||
@Parameter(name = ApiConstants.BR_POLICY_ID,
|
||||
type = CommandType.STRING,
|
||||
entityType = BackupRecoveryProviderResponse.class,
|
||||
required = true,
|
||||
description = "Backup Recovery Provider ID")
|
||||
private String policyId;
|
||||
|
||||
public Long getVirtualMachineId() {
|
||||
public String getVirtualMachineId() {
|
||||
return virtualMachineId;
|
||||
}
|
||||
|
||||
|
|
@ -68,12 +67,13 @@ public class AssignBackupPolicyCmd extends BaseCmd {
|
|||
}
|
||||
|
||||
@Inject
|
||||
BackupRecoveryManager backupRecoveryManager;
|
||||
BRManager brManager;
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
|
||||
try {
|
||||
boolean result = backupRecoveryManager.assignVMToBackupPolicy(this);
|
||||
BRProviderDriver provider = brManager.getBRProviderFromPolicy(getPolicyId());
|
||||
boolean result = provider.assignVMToBackupPolicy(getPolicyId(), getVirtualMachineId());
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
@ -82,13 +82,13 @@ public class AssignBackupPolicyCmd extends BaseCmd {
|
|||
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 AssignBackupPolicyCmd.APINAME + BaseCmd.RESPONSE_SUFFIX;
|
||||
return AssignBRPolicyCmd.APINAME + RESPONSE_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.framework.backuprecovery.api;
|
||||
package org.apache.cloudstack.api.command.admin.br.policy;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
|
@ -23,56 +23,53 @@ import org.apache.cloudstack.acl.RoleType;
|
|||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
|
||||
import org.apache.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 = ListBackupRecoveryPoliciesCmd.APINAME,
|
||||
@APICommand(name = ListBRPoliciesCmd.APINAME,
|
||||
description = "Lists mapped Backup policies",
|
||||
responseObject = BackupPolicyResponse.class, since = "4.12.0",
|
||||
responseObject = BRPolicyResponse.class, since = "4.12.0",
|
||||
authorized = {RoleType.Admin})
|
||||
public class ListBackupRecoveryPoliciesCmd extends BaseListCmd {
|
||||
public class ListBRPoliciesCmd extends BaseListCmd {
|
||||
|
||||
public static final String APINAME = "listBackupRecoveryPolicies";
|
||||
public static final String APINAME = "listBRPolicies";
|
||||
|
||||
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
|
||||
type = BaseCmd.CommandType.UUID,
|
||||
entityType = BackupRecoveryProviderResponse.class,
|
||||
@Parameter(name = ApiConstants.BR_PROVIDER_ID,
|
||||
type = CommandType.STRING,
|
||||
required = true,
|
||||
description = "Backup Recovery Provider ID")
|
||||
private Long providerId;
|
||||
private String providerId;
|
||||
|
||||
public long getProviderId() {
|
||||
public String getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
@Inject
|
||||
BackupRecoveryManager backupRecoveryManager;
|
||||
BRManager brManager;
|
||||
|
||||
@Override
|
||||
public void execute() throws ServerApiException, ConcurrentOperationException {
|
||||
try {
|
||||
ListResponse<BackupPolicyResponse> response = new ListResponse<BackupPolicyResponse>();
|
||||
List<BackupPolicyResponse> responses = new ArrayList<>();
|
||||
List<BackupPolicyVO> policies = backupRecoveryManager.listBackupPolicies(this);
|
||||
ListResponse<BRPolicyResponse> response = new ListResponse<BRPolicyResponse>();
|
||||
List<BRPolicyResponse> responses = new ArrayList<>();
|
||||
List<BRPolicy> policies = brManager.listBRPolicies(providerId);
|
||||
if (CollectionUtils.isNotEmpty(policies)) {
|
||||
for (BackupPolicyVO policy : policies) {
|
||||
BackupPolicyResponse p = backupRecoveryManager.createBackupPolicyResponse(policy);
|
||||
responses.add(p);
|
||||
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) {
|
||||
|
|
@ -83,7 +80,7 @@ public class ListBackupRecoveryPoliciesCmd extends BaseListCmd {
|
|||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
|
||||
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,15 +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.framework.backuprecovery.api;
|
||||
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.api.APICommand;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
|
|
@ -31,27 +29,26 @@ import org.apache.cloudstack.api.ApiErrorCode;
|
|||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
|
||||
import org.apache.cloudstack.br.BRManager;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
|
||||
import org.apache.cloudstack.api.response.BRProviderResponse;
|
||||
import org.apache.cloudstack.framework.br.BRProvider;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@APICommand(name = AddBackupRecoveryProviderCmd.APINAME,
|
||||
@APICommand(name = AddBRProviderCmd.APINAME,
|
||||
description = "Adds a Backup and Recovery provider on a zone",
|
||||
responseObject = BackupRecoveryProviderResponse.class, since = "4.12.0",
|
||||
responseObject = BRProviderResponse.class, since = "4.12.0",
|
||||
authorized = {RoleType.Admin})
|
||||
public class AddBackupRecoveryProviderCmd extends BaseCmd {
|
||||
public class AddBRProviderCmd extends BaseCmd {
|
||||
|
||||
public static final String APINAME = "addBackupRecoveryProvider";
|
||||
public static final String APINAME = "addBRProvider";
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(AddBackupRecoveryProviderCmd.class);
|
||||
private static final Logger s_logger = Logger.getLogger(AddBRProviderCmd.class);
|
||||
|
||||
@Inject
|
||||
BackupRecoveryManager backupRecoveryManager;
|
||||
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.")
|
||||
|
|
@ -74,34 +71,20 @@ public class AddBackupRecoveryProviderCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
|
||||
try {
|
||||
BackupRecoveryProviderVO providerVO = backupRecoveryManager.addBackupRecoveryProvider(this);
|
||||
if (providerVO != null) {
|
||||
BackupRecoveryProviderResponse response = backupRecoveryManager.createBackupRecoveryProviderResponse(providerVO);
|
||||
response.setObjectName("backuprecoveryprovider");
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add a Backup and Recovery Provider");
|
||||
}
|
||||
} catch (InvalidParameterValueException e) {
|
||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
|
||||
} catch (CloudRuntimeException e) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
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() + BaseCmd.RESPONSE_SUFFIX;
|
||||
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.api;
|
||||
package org.apache.cloudstack.api.command.admin.br.provider;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
|
|
@ -33,37 +33,35 @@ import org.apache.cloudstack.api.ApiConstants;
|
|||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import org.apache.cloudstack.br.BRManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@APICommand(name = DeleteBackupRecoveryProviderCmd.APINAME,
|
||||
@APICommand(name = DeleteBRProviderCmd.APINAME,
|
||||
description = "Deletes a Backup and Recovery provider",
|
||||
responseObject = SuccessResponse.class, since = "4.12.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
|
||||
responseObject = SuccessResponse.class, since = "4.12.0",
|
||||
authorized = {RoleType.Admin})
|
||||
public class DeleteBackupRecoveryProviderCmd extends BaseCmd {
|
||||
public class DeleteBRProviderCmd extends BaseCmd {
|
||||
|
||||
public static final String APINAME = "deleteBackupRecoveryProvider";
|
||||
public static final String APINAME = "deleteBRProvider";
|
||||
|
||||
@Inject
|
||||
BackupRecoveryManager backupRecoveryManager;
|
||||
BRManager brManager;
|
||||
|
||||
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
|
||||
type = CommandType.UUID,
|
||||
entityType = BackupRecoveryProviderResponse.class,
|
||||
@Parameter(name = ApiConstants.BR_PROVIDER_ID,
|
||||
type = CommandType.STRING,
|
||||
required = true,
|
||||
description = "Backup Recovery Provider ID")
|
||||
private Long providerId;
|
||||
private String providerId;
|
||||
|
||||
public Long getProviderId() {
|
||||
public String getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
|
||||
try {
|
||||
boolean result = backupRecoveryManager.deleteBackupRecoveryProvider(this);
|
||||
boolean result = brManager.deleteBRProvider(providerId);
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
@ -80,7 +78,7 @@ public class DeleteBackupRecoveryProviderCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
|
||||
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -15,71 +15,76 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.api;
|
||||
package org.apache.cloudstack.api.command.admin.br.provider;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import 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 javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@APICommand(name = ListBackupRecoveryProviderPoliciesCmd.APINAME,
|
||||
@APICommand(name = ListBRProviderPoliciesCmd.APINAME,
|
||||
description = "Lists Backup policies existing on the Backup and Recovery provider side",
|
||||
responseObject = BackupRecoveryProviderPolicyResponse.class, since = "4.12.0",
|
||||
responseObject = BRPolicyResponse.class, since = "4.12.0",
|
||||
authorized = {RoleType.Admin})
|
||||
public class ListBackupRecoveryProviderPoliciesCmd extends BaseListCmd {
|
||||
public class ListBRProviderPoliciesCmd extends BaseListCmd {
|
||||
|
||||
public static final String APINAME = "listBackupRecoveryProviderPolicies";
|
||||
public static final String APINAME = "listBRProviderPolicies";
|
||||
|
||||
@Inject
|
||||
BackupRecoveryManager backupRecoveryManager;
|
||||
BRManager brManager;
|
||||
|
||||
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
|
||||
type = BaseCmd.CommandType.UUID,
|
||||
entityType = BackupRecoveryProviderResponse.class,
|
||||
@Parameter(name = ApiConstants.BR_PROVIDER_ID,
|
||||
type = CommandType.STRING,
|
||||
required = true,
|
||||
description = "Backup Recovery Provider ID")
|
||||
private Long providerId;
|
||||
private String providerId;
|
||||
|
||||
public Long getProviderId() {
|
||||
public String getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, ServerApiException, ConcurrentOperationException {
|
||||
List<BRPolicyResponse> responses = new ArrayList<>();
|
||||
ListResponse<BRPolicyResponse> response = new ListResponse<BRPolicyResponse>();
|
||||
try {
|
||||
ListResponse<BackupRecoveryProviderPolicyResponse> response = new ListResponse<BackupRecoveryProviderPolicyResponse>();
|
||||
List<BackupRecoveryProviderPolicyResponse> policies = backupRecoveryManager.listBackupPolicies(this);
|
||||
BRProviderDriver provider = brManager.getBRProviderFromProvider(providerId);
|
||||
List<BRPolicy> policies = provider.listBackupPolicies(brManager.getProviderId(providerId));
|
||||
if (policies == null) {
|
||||
throw new CloudRuntimeException("Error while retrieving backup provider policies");
|
||||
}
|
||||
response.setResponses(policies, policies.size());
|
||||
for (BRPolicy policy : policies) {
|
||||
responses.add(brManager.createBackupPolicyResponse(policy));
|
||||
}
|
||||
response.setResponses(responses, responses.size());
|
||||
response.setObjectName("brproviderpolicies");
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} catch (InvalidParameterValueException e) {
|
||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
|
||||
} catch (CloudRuntimeException | OperationTimedoutException e) {
|
||||
} catch (CloudRuntimeException e) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
|
||||
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,72 +15,53 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.api;
|
||||
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.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
|
||||
import org.apache.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 = ListBackupRecoveryProvidersCmd.APINAME,
|
||||
@APICommand(name = ListBRProvidersCmd.APINAME,
|
||||
description = "Lists Backup and Recovery providers",
|
||||
responseObject = BackupRecoveryProviderResponse.class, since = "4.12.0",
|
||||
responseObject = BRProviderResponse.class, since = "4.12.0",
|
||||
authorized = {RoleType.Admin})
|
||||
public class ListBackupRecoveryProvidersCmd extends BaseListCmd {
|
||||
public class ListBRProvidersCmd extends BaseListCmd {
|
||||
|
||||
public static final String APINAME = "listBackupRecoveryProviders";
|
||||
public static final String APINAME = "listBRProviders";
|
||||
|
||||
@Inject
|
||||
BackupRecoveryManager backupRecoveryManager;
|
||||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
|
||||
description="the ID of the zone")
|
||||
private Long zoneId;
|
||||
|
||||
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, entityType = BackupRecoveryProviderResponse.class,
|
||||
description = "the Backup and Recovery provider type")
|
||||
private String provider;
|
||||
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return provider;
|
||||
}
|
||||
BRManager brManager;
|
||||
|
||||
@Override
|
||||
public void execute() throws ServerApiException, ConcurrentOperationException {
|
||||
try {
|
||||
List<BackupRecoveryProviderVO> providers = backupRecoveryManager.listBackupRecoveryProviders(this);
|
||||
ListResponse<BackupRecoveryProviderResponse> response = new ListResponse<BackupRecoveryProviderResponse>();
|
||||
List<BackupRecoveryProviderResponse> providersResponse = new ArrayList<BackupRecoveryProviderResponse>();
|
||||
List<BRProvider> providers = brManager.listBRProviders();
|
||||
ListResponse<BRProviderResponse> response = new ListResponse<BRProviderResponse>();
|
||||
List<BRProviderResponse> providersResponse = new ArrayList<BRProviderResponse>();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(providers)) {
|
||||
for (BackupRecoveryProviderVO providerVO : providers) {
|
||||
BackupRecoveryProviderResponse providerResponse = backupRecoveryManager.createBackupRecoveryProviderResponse(providerVO);
|
||||
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) {
|
||||
|
|
@ -92,6 +73,6 @@ public class ListBackupRecoveryProvidersCmd extends BaseListCmd {
|
|||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
|
||||
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,34 +15,38 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.api.response;
|
||||
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.backuprecovery.impl.BackupPolicyVO;
|
||||
import org.apache.cloudstack.framework.br.BRPolicy;
|
||||
|
||||
@EntityReference(value = BackupPolicyVO.class)
|
||||
public class BackupPolicyResponse extends BaseResponse {
|
||||
@EntityReference(value = BRPolicy.class)
|
||||
public class BRPolicyResponse extends BaseResponse {
|
||||
|
||||
@SerializedName(ApiConstants.ID)
|
||||
@Param(description = "internal id of the Backup policy")
|
||||
@Param(description = "internal id of the backup policy")
|
||||
private String id;
|
||||
|
||||
@SerializedName(ApiConstants.BACKUP_POLICY_ID)
|
||||
@SerializedName(ApiConstants.UUID)
|
||||
@Param(description = "internal uuid of the backup policy")
|
||||
private String uuid;
|
||||
|
||||
@SerializedName(ApiConstants.NAME)
|
||||
@Param(description = "internal name for the backup policy")
|
||||
private String name;
|
||||
|
||||
@SerializedName(ApiConstants.BR_POLICY_ID)
|
||||
@Param(description = "policy id on the provider side")
|
||||
private String policyId;
|
||||
|
||||
@SerializedName(ApiConstants.BACKUP_PROVIDER_ID)
|
||||
@Param(description = "id of the Backup and Recovery provider")
|
||||
@SerializedName(ApiConstants.BR_PROVIDER_ID)
|
||||
@Param(description = "id of the backup and Recovery provider")
|
||||
private String providerId;
|
||||
|
||||
@SerializedName(ApiConstants.BACKUP_POLICY_NAME)
|
||||
@Param(description = "internal name for the backup policy")
|
||||
private String name;
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
|
@ -58,4 +62,8 @@ public class BackupPolicyResponse extends BaseResponse {
|
|||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,19 +15,19 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.api.response;
|
||||
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.backuprecovery.impl.BackupRecoveryProviderVO;
|
||||
import org.apache.cloudstack.framework.br.BRProvider;
|
||||
|
||||
@EntityReference(value = BackupRecoveryProviderVO.class)
|
||||
public class BackupRecoveryProviderResponse extends BaseResponse {
|
||||
@EntityReference(BRProvider.class)
|
||||
public class BRProviderResponse extends BaseResponse {
|
||||
|
||||
@SerializedName(ApiConstants.BACKUP_PROVIDER_ID)
|
||||
@SerializedName(ApiConstants.BR_PROVIDER_ID)
|
||||
@Param(description = "id of the Backup and Recovery provider")
|
||||
private String id;
|
||||
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.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);
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
// 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.Adapter;
|
||||
import org.apache.cloudstack.framework.br.BRPolicy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Backup and Recovery Provider
|
||||
*/
|
||||
public interface BRProviderDriver extends Adapter {
|
||||
|
||||
/**
|
||||
* Register Backup and Recovery Provider
|
||||
*/
|
||||
boolean registerProvider(long zoneId, String name, String url, String username, String password);
|
||||
|
||||
/**
|
||||
* True if policy exists on the provider, false if not
|
||||
*/
|
||||
boolean policyExists(String policyId, String policyName);
|
||||
|
||||
/**
|
||||
* List existing Backup Policies on the provider
|
||||
*/
|
||||
List<BRPolicy> listBackupPolicies(long providerId);
|
||||
|
||||
/**
|
||||
* Assign a VM to an existing backup policy
|
||||
*/
|
||||
boolean assignVMToBackupPolicy(String policyId, String vmId);
|
||||
|
||||
/**
|
||||
* Unregister Backup and Recovery Provider
|
||||
*/
|
||||
boolean unregisterProvider();
|
||||
|
||||
void restoreVMFromBackup();
|
||||
void restoreAndAttachVolumeToVM();
|
||||
}
|
||||
|
|
@ -26,12 +26,7 @@
|
|||
|
||||
<bean class="org.apache.cloudstack.spring.lifecycle.registry.RegistryLifecycle">
|
||||
<property name="registry" ref="backupRecoveryRegistry" />
|
||||
<property name="typeClass" value="org.apache.cloudstack.framework.backuprecovery.BackupRecoveryProvider" />
|
||||
<property name="typeClass" value="org.apache.cloudstack.br.BRProviderDriver" />
|
||||
</bean>
|
||||
|
||||
<bean id="backupRecoveryProviderDaoImpl" class="org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderDaoImpl" />
|
||||
<bean id="backupPoliciesDaoImpl" class="org.apache.cloudstack.framework.backuprecovery.impl.BackupPoliciesDaoImpl" />
|
||||
|
||||
<bean id="backupRecoveryManagerImpl" class="org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryManagerImpl" />
|
||||
|
||||
</beans>
|
||||
|
|
@ -17,31 +17,47 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.agent.api.to;
|
||||
package org.apache.cloudstack.br;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.apache.cloudstack.framework.br.BRPolicy;
|
||||
|
||||
public class BackupPolicyTO implements Serializable {
|
||||
public class BRPolicyTO implements BRPolicy {
|
||||
|
||||
private long id;
|
||||
private String uuid;
|
||||
private String name;
|
||||
private String id;
|
||||
private String description;
|
||||
private String policyUuid;
|
||||
private long providerId;
|
||||
|
||||
public BackupPolicyTO(final String id, final String name, final String desc) {
|
||||
this.id = id;
|
||||
public BRPolicyTO(final long id, final String uuid, final String name, final String policyUuid, final long providerId) {
|
||||
this.name = name;
|
||||
this.description = desc;
|
||||
this.uuid = uuid;
|
||||
this.id = id;
|
||||
this.policyUuid = policyUuid;
|
||||
this.providerId = providerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPolicyUuid() {
|
||||
return policyUuid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@Override
|
||||
public long getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,10 +15,9 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.impl;
|
||||
package org.apache.cloudstack.br;
|
||||
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
import org.apache.cloudstack.framework.br.BRPolicy;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
|
@ -29,14 +28,14 @@ import javax.persistence.Table;
|
|||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "backup_policies")
|
||||
public class BackupPolicyVO implements InternalIdentity, Identity {
|
||||
@Table(name = "br_policies")
|
||||
public class BRPolicyVO implements BRPolicy {
|
||||
|
||||
public BackupPolicyVO() {
|
||||
public BRPolicyVO() {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public BackupPolicyVO(final long providerId, final String name, final String policyUuid) {
|
||||
public BRPolicyVO(final long providerId, final String name, final String policyUuid) {
|
||||
this();
|
||||
this.providerId = providerId;
|
||||
this.name = name;
|
||||
|
|
@ -59,14 +58,12 @@ public class BackupPolicyVO implements InternalIdentity, Identity {
|
|||
@Column(name = "policy_uuid")
|
||||
private String policyUuid;
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return null;
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return 0;
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
// 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,10 +14,9 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.framework.backuprecovery.impl;
|
||||
package org.apache.cloudstack.br;
|
||||
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
import org.apache.cloudstack.framework.br.BRProvider;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
|
@ -28,18 +27,17 @@ import javax.persistence.GenerationType;
|
|||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "backup_and_recovery_providers")
|
||||
public class BackupRecoveryProviderVO implements InternalIdentity, Identity {
|
||||
@Table(name = "br_provider")
|
||||
public class BRProviderVO implements BRProvider {
|
||||
|
||||
public BackupRecoveryProviderVO() {
|
||||
public BRProviderVO() {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public BackupRecoveryProviderVO(final long hostId, final String name, final long zoneId, final String url, final String provider) {
|
||||
public BRProviderVO(final String name, final long zoneId, final String url, final String provider) {
|
||||
this();
|
||||
this.name = name;
|
||||
this.zoneId = zoneId;
|
||||
this.hostId = hostId;
|
||||
this.provider = provider;
|
||||
this.url = url;
|
||||
}
|
||||
|
|
@ -51,9 +49,6 @@ public class BackupRecoveryProviderVO implements InternalIdentity, Identity {
|
|||
@Column(name = "uuid")
|
||||
private String uuid;
|
||||
|
||||
@Column(name = "host_id")
|
||||
private long hostId;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
|
|
@ -83,14 +78,6 @@ public class BackupRecoveryProviderVO implements InternalIdentity, Identity {
|
|||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public long getHostId() {
|
||||
return hostId;
|
||||
}
|
||||
|
||||
public void setHostId(long hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
@ -15,14 +15,15 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.dao;
|
||||
package org.apache.cloudstack.br.dao;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
|
||||
import org.apache.cloudstack.br.BRPolicyVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BackupPoliciesDao extends GenericDao<BackupPolicyVO, Long> {
|
||||
public interface BRPoliciesDao extends GenericDao<BRPolicyVO, Long> {
|
||||
|
||||
List<BackupPolicyVO> listByProvider(long providerId);
|
||||
List<BRPolicyVO> listByProvider(long providerId);
|
||||
void removeByProvider(long providerId);
|
||||
}
|
||||
|
|
@ -15,23 +15,23 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.impl;
|
||||
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.framework.backuprecovery.dao.BackupPoliciesDao;
|
||||
import org.apache.cloudstack.br.BRPolicyVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class BackupPoliciesDaoImpl extends GenericDaoBase<BackupPolicyVO, Long> implements BackupPoliciesDao {
|
||||
public class BRPoliciesDaoImpl extends GenericDaoBase<BRPolicyVO, Long> implements BRPoliciesDao {
|
||||
|
||||
protected SearchBuilder<BackupPolicyVO> backupPoliciesSearch;
|
||||
protected SearchBuilder<BRPolicyVO> backupPoliciesSearch;
|
||||
|
||||
public BackupPoliciesDaoImpl() {
|
||||
public BRPoliciesDaoImpl() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
|
|
@ -42,9 +42,18 @@ public class BackupPoliciesDaoImpl extends GenericDaoBase<BackupPolicyVO, Long>
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<BackupPolicyVO> listByProvider(long providerId) {
|
||||
SearchCriteria<BackupPolicyVO> sc = backupPoliciesSearch.create();
|
||||
public List<BRPolicyVO> listByProvider(long providerId) {
|
||||
SearchCriteria<BRPolicyVO> sc = backupPoliciesSearch.create();
|
||||
sc.setParameters("provider", providerId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByProvider(long providerId) {
|
||||
SearchCriteria<BRPolicyVO> sc = backupPoliciesSearch.create();
|
||||
sc.setParameters("provider", providerId);
|
||||
expunge(sc);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -14,15 +14,15 @@
|
|||
// 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;
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.agent.api;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import org.apache.cloudstack.br.BRProviderVO;
|
||||
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.host.Host;
|
||||
import java.util.List;
|
||||
|
||||
public class StartupBackupRecoveryProviderCommand extends StartupCommand {
|
||||
public interface BRProviderDao extends GenericDao<BRProviderVO, Long> {
|
||||
|
||||
public StartupBackupRecoveryProviderCommand() {
|
||||
super(Host.Type.BackupRecovery);
|
||||
}
|
||||
List<BRProviderVO> listByZone(long zoneId);
|
||||
List<BRProviderVO> listByZoneAndProvider(long zoneId, String provider);
|
||||
}
|
||||
|
|
@ -14,43 +14,43 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.framework.backuprecovery.impl;
|
||||
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.framework.backuprecovery.dao.BackupRecoveryProviderDao;
|
||||
import org.apache.cloudstack.br.BRProviderVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class BackupRecoveryProviderDaoImpl extends GenericDaoBase<BackupRecoveryProviderVO, Long> implements BackupRecoveryProviderDao {
|
||||
public class BRProviderDaoImpl extends GenericDaoBase<BRProviderVO, Long> implements BRProviderDao {
|
||||
|
||||
protected SearchBuilder<BackupRecoveryProviderVO> backupProviderSearch;
|
||||
protected SearchBuilder<BRProviderVO> brProviderSearch;
|
||||
|
||||
public BackupRecoveryProviderDaoImpl() {
|
||||
public BRProviderDaoImpl() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
backupProviderSearch = createSearchBuilder();
|
||||
backupProviderSearch.and("zoneid", backupProviderSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||
backupProviderSearch.and("provider", backupProviderSearch.entity().getProviderName(), SearchCriteria.Op.EQ);
|
||||
backupProviderSearch.done();
|
||||
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<BackupRecoveryProviderVO> listByZone(long zoneId) {
|
||||
SearchCriteria<BackupRecoveryProviderVO> sc = backupProviderSearch.create();
|
||||
public List<BRProviderVO> listByZone(long zoneId) {
|
||||
SearchCriteria<BRProviderVO> sc = brProviderSearch.create();
|
||||
sc.setParameters("zoneid", zoneId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BackupRecoveryProviderVO> listByZoneAndProvider(long zoneId, String provider) {
|
||||
SearchCriteria<BackupRecoveryProviderVO> sc = backupProviderSearch.create();
|
||||
public List<BRProviderVO> listByZoneAndProvider(long zoneId, String provider) {
|
||||
SearchCriteria<BRProviderVO> sc = brProviderSearch.create();
|
||||
sc.setParameters("zoneid", zoneId);
|
||||
sc.setParameters("provider", provider);
|
||||
return listBy(sc);
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
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<BRProviderDetailVO, Long> {
|
||||
|
||||
void addDetails(List<BRProviderDetailVO> details);
|
||||
void removeDetails(long providerId);
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.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<BRProviderDetailVO, Long> implements BRProviderDetailsDao {
|
||||
|
||||
protected SearchBuilder<BRProviderDetailVO> detailsSearch;
|
||||
|
||||
@PostConstruct
|
||||
protected void init() {
|
||||
detailsSearch = createSearchBuilder();
|
||||
detailsSearch.and("provider", detailsSearch.entity().getProviderId(), SearchCriteria.Op.EQ);
|
||||
detailsSearch.done();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addDetails(List<BRProviderDetailVO> details) {
|
||||
for (BRProviderDetailVO detail : details) {
|
||||
persist(detail);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDetails(long providerId) {
|
||||
SearchCriteria<BRProviderDetailVO> sc = detailsSearch.create();
|
||||
sc.setParameters("provider", providerId);
|
||||
remove(sc);
|
||||
}
|
||||
}
|
||||
|
|
@ -356,4 +356,7 @@
|
|||
<bean id="outOfBandManagementDaoImpl" class="org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDaoImpl" />
|
||||
<bean id="GuestOsDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.GuestOsDetailsDaoImpl" />
|
||||
<bean id="annotationDaoImpl" class="org.apache.cloudstack.annotation.dao.AnnotationDaoImpl" />
|
||||
<bean id="brProviderDaoImpl" class="org.apache.cloudstack.br.dao.BRProviderDaoImpl" />
|
||||
<bean id="brProviderDetailsDaoImpl" class="org.apache.cloudstack.br.dao.BRProviderDetailsDaoImpl" />
|
||||
<bean id="brPoliciesDaoImpl" class="org.apache.cloudstack.br.dao.BRPoliciesDaoImpl" />
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -36,22 +36,30 @@ INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`,
|
|||
|
||||
-- Backup and Recovery
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `cloud`.`backup_and_recovery_providers` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||
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',
|
||||
`host_id` bigint(20) unsigned NOT NULL COMMENT 'host id coresponding to the backup and recovery provider',
|
||||
`provider` varchar(255) DEFAULT NULL COMMENT 'the backup and recovery provider',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uuid` (`uuid`),
|
||||
KEY `fk_backup_and_recovery_providers__host_id` (`host_id`),
|
||||
CONSTRAINT `fk_backup_and_recovery_providers__host_id` FOREIGN KEY (`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `fk_backup_and_recovery_providers__zone_id` FOREIGN KEY (`zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `cloud`.`backup_policies` (
|
||||
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` (
|
||||
`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',
|
||||
|
|
@ -59,5 +67,5 @@ CREATE TABLE IF NOT EXISTS `cloud`.`backup_policies` (
|
|||
`policy_uuid` varchar(40) NOT NULL COMMENT 'backup policy ID on provider side',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uuid` (`uuid`),
|
||||
CONSTRAINT `fk_backup_polocies__provider_id` FOREIGN KEY (`provider_id`) REFERENCES `backup_and_recovery_providers` (`id`) ON DELETE CASCADE
|
||||
CONSTRAINT `fk_br_policies__provider_id` FOREIGN KEY (`provider_id`) REFERENCES `br_provider` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
|
|
|||
|
|
@ -28,33 +28,5 @@
|
|||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-engine-components-api</artifactId>
|
||||
<version>4.12.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-server</artifactId>
|
||||
<version>4.12.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-server</artifactId>
|
||||
<version>4.12.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,28 +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.backuprecovery;
|
||||
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import org.apache.cloudstack.framework.config.Configurable;
|
||||
|
||||
/**
|
||||
* Backup and Recover Manager Interface
|
||||
*/
|
||||
public interface BackupRecoveryManager extends BackupRecoveryService, BackupRecoveryProvider, Configurable, PluggableService {
|
||||
|
||||
}
|
||||
|
|
@ -1,60 +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.backuprecovery;
|
||||
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryPolicyCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.AssignBackupPolicyCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryPoliciesCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProviderPoliciesCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Backup and Recovery Provider
|
||||
*/
|
||||
public interface BackupRecoveryProvider extends Adapter {
|
||||
|
||||
/**
|
||||
* List existing Backup Policies on the provider
|
||||
*/
|
||||
List<BackupRecoveryProviderPolicyResponse> listBackupPolicies(ListBackupRecoveryProviderPoliciesCmd cmd) throws AgentUnavailableException, OperationTimedoutException;
|
||||
|
||||
/**
|
||||
* List backup policies mapped to provider policies
|
||||
*/
|
||||
List<BackupPolicyVO> listBackupPolicies(ListBackupRecoveryPoliciesCmd cmd);
|
||||
|
||||
/**
|
||||
* Add a Backup Policy by mapping it to a policy on the provider
|
||||
*/
|
||||
BackupPolicyVO addBackupPolicy(AddBackupRecoveryPolicyCmd cmd) throws AgentUnavailableException, OperationTimedoutException;
|
||||
|
||||
/**
|
||||
* Assign a VM to an existing backup policy
|
||||
*/
|
||||
boolean assignVMToBackupPolicy(AssignBackupPolicyCmd cmd) throws AgentUnavailableException, OperationTimedoutException;
|
||||
|
||||
void restoreVMFromBackup();
|
||||
void restoreAndAttachVolumeToVM();
|
||||
|
||||
}
|
||||
|
|
@ -1,59 +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.backuprecovery;
|
||||
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryProviderCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.DeleteBackupRecoveryProviderCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProvidersCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
public interface BackupRecoveryService {
|
||||
|
||||
/**
|
||||
* Add a new Backup and Recovery provider
|
||||
*/
|
||||
BackupRecoveryProviderVO addBackupRecoveryProvider(AddBackupRecoveryProviderCmd cmd) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException;
|
||||
|
||||
/**
|
||||
* Delete existing Backup and Recovery provider
|
||||
*/
|
||||
boolean deleteBackupRecoveryProvider(DeleteBackupRecoveryProviderCmd cmd);
|
||||
|
||||
/**
|
||||
* List existing Backup and Recovery providers
|
||||
* @param cmd
|
||||
* @return
|
||||
*/
|
||||
List<BackupRecoveryProviderVO> listBackupRecoveryProviders(ListBackupRecoveryProvidersCmd cmd);
|
||||
|
||||
/**
|
||||
* Generate a response from the Backup and Recovery Provider VO
|
||||
*/
|
||||
BackupRecoveryProviderResponse createBackupRecoveryProviderResponse(BackupRecoveryProviderVO backupRecoveryProviderVO);
|
||||
|
||||
/**
|
||||
* Generate a response from the Backup Policy VO
|
||||
*/
|
||||
BackupPolicyResponse createBackupPolicyResponse(BackupPolicyVO policyVO);
|
||||
}
|
||||
|
|
@ -1,30 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
public class AssignVMToBackupPolicyAnswer extends Answer {
|
||||
|
||||
public AssignVMToBackupPolicyAnswer(final boolean result) {
|
||||
super(null);
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class AssignVMToBackupPolicyCommand extends Command {
|
||||
|
||||
private long vmId;
|
||||
private String vmUuid;
|
||||
private String backupPolicyUuid;
|
||||
|
||||
public AssignVMToBackupPolicyCommand(final long vmId, final String vmUuid, final String backupPolicyUuid) {
|
||||
this.vmId = vmId;
|
||||
this.vmUuid = vmUuid;
|
||||
this.backupPolicyUuid = backupPolicyUuid;
|
||||
}
|
||||
|
||||
public long getVmId() {
|
||||
return vmId;
|
||||
}
|
||||
|
||||
public String getVmUuid() {
|
||||
return vmUuid;
|
||||
}
|
||||
|
||||
public String getBackupPolicyUuid() {
|
||||
return backupPolicyUuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
public class CheckBackupPolicyAnswer extends Answer {
|
||||
|
||||
public CheckBackupPolicyAnswer(final boolean result) {
|
||||
super(null);
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class CheckBackupPolicyCommand extends Command {
|
||||
|
||||
private String policyUuid;
|
||||
|
||||
public CheckBackupPolicyCommand(final String policyUuid) {
|
||||
this.policyUuid = policyUuid;
|
||||
}
|
||||
|
||||
public String getPolicyUuid() {
|
||||
return policyUuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ImportBackupPoliciesAnswer extends Answer {
|
||||
|
||||
private List<String> backupPolicies;
|
||||
|
||||
public ImportBackupPoliciesAnswer(final boolean result, final List<String> backupPolicies) {
|
||||
super(null);
|
||||
this.result = result;
|
||||
this.backupPolicies = backupPolicies;
|
||||
}
|
||||
|
||||
public List<String> getBackupPolicies() {
|
||||
return backupPolicies;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ListBackupPoliciesAnswer extends Answer {
|
||||
|
||||
private List<BackupPolicyTO> policies;
|
||||
|
||||
public ListBackupPoliciesAnswer(final boolean result, final List<BackupPolicyTO> policies) {
|
||||
super(null);
|
||||
this.result = result;
|
||||
this.policies = policies;
|
||||
}
|
||||
|
||||
public List<BackupPolicyTO> getPolicies() {
|
||||
return policies;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class ListBackupPoliciesCommand extends Command {
|
||||
|
||||
private String zoneUuid;
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ListBackupPoliciesCommand(String zoneUuid) {
|
||||
this.zoneUuid = zoneUuid;
|
||||
}
|
||||
|
||||
public String getZoneUuid() {
|
||||
return zoneUuid;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ListBackupsAnswer extends Answer {
|
||||
|
||||
private List<String> backups;
|
||||
|
||||
public ListBackupsAnswer(final boolean result, final List<String> backups) {
|
||||
super(null);
|
||||
this.result = result;
|
||||
this.backups = backups;
|
||||
}
|
||||
|
||||
public List<String> getBackups() {
|
||||
return backups;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class ListBackupsCommand extends Command {
|
||||
|
||||
private Long vmId;
|
||||
|
||||
public ListBackupsCommand(final Long vmId) {
|
||||
this.vmId = vmId;
|
||||
}
|
||||
|
||||
public Long getVmId() {
|
||||
return vmId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +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.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
public class RestoreVMFromBackupAnswer extends Answer {
|
||||
|
||||
public RestoreVMFromBackupAnswer(final boolean result) {
|
||||
super(null);
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
@ -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.framework.backuprecovery.agent.api;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class RestoreVMFromBackupCommand extends Command {
|
||||
|
||||
private long vmId;
|
||||
private String vmUuid;
|
||||
private long backupId;
|
||||
private String backupUuid;
|
||||
|
||||
public RestoreVMFromBackupCommand(final long vmId, final String vmUuid, final long backupId, final String backupUuid) {
|
||||
this.vmId = vmId;
|
||||
this.vmUuid = vmUuid;
|
||||
this.backupId = backupId;
|
||||
this.backupUuid = backupUuid;
|
||||
}
|
||||
|
||||
public long getVmId() {
|
||||
return vmId;
|
||||
}
|
||||
|
||||
public String getVmUuid() {
|
||||
return vmUuid;
|
||||
}
|
||||
|
||||
public long getBackupId() {
|
||||
return backupId;
|
||||
}
|
||||
|
||||
public String getBackupUuid() {
|
||||
return backupUuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -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.framework.backuprecovery.api.response;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
|
||||
/**
|
||||
* Response for a Backup Policy on the provider
|
||||
*/
|
||||
public class BackupRecoveryProviderPolicyResponse extends BaseResponse {
|
||||
|
||||
@SerializedName(ApiConstants.BACKUP_POLICY_ID)
|
||||
@Param(description = "policy id on the provider side")
|
||||
private String policyId;
|
||||
|
||||
@SerializedName(ApiConstants.BACKUP_POLICY_NAME)
|
||||
@Param(description = "name for the backup policy on the provider side")
|
||||
private String name;
|
||||
|
||||
@SerializedName(ApiConstants.DESCRIPTION)
|
||||
@Param(description = "description for the backup policy on the provider side")
|
||||
private String description;
|
||||
|
||||
public void setPolicyId(String policyId) {
|
||||
this.policyId = policyId;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDescription(String desc) {
|
||||
this.description = desc;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +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.backuprecovery.dao;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BackupRecoveryProviderDao extends GenericDao<BackupRecoveryProviderVO, Long> {
|
||||
|
||||
List<BackupRecoveryProviderVO> listByZone(long zoneId);
|
||||
List<BackupRecoveryProviderVO> listByZoneAndProvider(long zoneId, String provider);
|
||||
}
|
||||
|
|
@ -1,79 +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.backuprecovery.element;
|
||||
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceStateAdapter;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.resource.UnableDeleteHostException;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.StartupBackupRecoveryProviderCommand;
|
||||
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Backup and Recovery Element class.
|
||||
* To register a Backup and Recovery element, just extend this class
|
||||
*/
|
||||
public class BackupRecoveryElement extends AdapterBase implements ResourceStateAdapter, BackupRecoveryElementService {
|
||||
|
||||
@Inject
|
||||
ResourceManager resourceManager;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
resourceManager.registerResourceStateAdapter(name, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
|
||||
if (!(startup[0] instanceof StartupBackupRecoveryProviderCommand)) {
|
||||
return null;
|
||||
}
|
||||
host.setType(Host.Type.BackupRecovery);
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
||||
if (!(host.getType() == Host.Type.BackupRecovery)) {
|
||||
return null;
|
||||
}
|
||||
return new DeleteHostAnswer(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackupRecoveryResource createNewResource() {
|
||||
return new BackupRecoveryResource();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +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.backuprecovery.helper;
|
||||
|
||||
import org.apache.cloudstack.framework.backuprecovery.element.BackupRecoveryElement;
|
||||
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BackupRecoveryHelper {
|
||||
|
||||
/**
|
||||
* Backup and Recovery Providers Helper
|
||||
*/
|
||||
|
||||
private static Map<String, BackupRecoveryElement> supportedProviders = new HashMap<String, BackupRecoveryElement>();
|
||||
|
||||
public static boolean isProviderSupported(String providerName) {
|
||||
return supportedProviders.containsKey(providerName);
|
||||
}
|
||||
|
||||
public static void addProvider(String providerName, BackupRecoveryElement element) {
|
||||
supportedProviders.put(providerName, element);
|
||||
}
|
||||
|
||||
public static BackupRecoveryResource getResource(String name) {
|
||||
if (supportedProviders.containsKey(name)) {
|
||||
BackupRecoveryElement element = supportedProviders.get(name);
|
||||
return element.createNewResource();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,323 +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.backuprecovery.impl;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.TransactionCallback;
|
||||
import com.cloud.utils.db.TransactionStatus;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyAnswer;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyCommand;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyAnswer;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyCommand;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesAnswer;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesCommand;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryPolicyCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryProviderCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.AssignBackupPolicyCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.DeleteBackupRecoveryProviderCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryPoliciesCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProviderPoliciesCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProvidersCmd;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
|
||||
import org.apache.cloudstack.framework.backuprecovery.dao.BackupPoliciesDao;
|
||||
import org.apache.cloudstack.framework.backuprecovery.dao.BackupRecoveryProviderDao;
|
||||
import org.apache.cloudstack.framework.backuprecovery.helper.BackupRecoveryHelper;
|
||||
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BackupRecoveryManagerImpl extends ManagerBase implements BackupRecoveryManager {
|
||||
|
||||
@Inject
|
||||
BackupRecoveryProviderDao backupRecoveryProviderDao;
|
||||
@Inject
|
||||
HostDetailsDao hostDetailsDao;
|
||||
@Inject
|
||||
ResourceManager resourceManager;
|
||||
@Inject
|
||||
HostDao hostDao;
|
||||
@Inject
|
||||
DataCenterDao dataCenterDao;
|
||||
@Inject
|
||||
BackupPoliciesDao backupPoliciesDao;
|
||||
@Inject
|
||||
AgentManager agentManager;
|
||||
@Inject
|
||||
VMInstanceDao vmInstanceDao;
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(BackupRecoveryManagerImpl.class);
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackupRecoveryProviderVO addBackupRecoveryProvider(AddBackupRecoveryProviderCmd cmd) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||
String name = cmd.getName();
|
||||
String url = cmd.getUrl();
|
||||
String username = cmd.getUsername();
|
||||
String password = cmd.getPassword();
|
||||
Long zoneId = cmd.getZoneId();
|
||||
String providerName = cmd.getProvider();
|
||||
|
||||
if (!BackupRecoveryHelper.isProviderSupported(providerName)) {
|
||||
throw new InvalidParameterException("Unsopported provider: " + providerName);
|
||||
}
|
||||
|
||||
s_logger.debug("Registering a new Backup and Recovery provider on zone: " + zoneId + " - url: " + url + " - name: " + name
|
||||
+ " - provider: " + providerName);
|
||||
BackupRecoveryResource resource = BackupRecoveryHelper.getResource(providerName);
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("guid", UUID.randomUUID().toString());
|
||||
params.put("zoneId", String.valueOf(zoneId));
|
||||
params.put("name", name + " - " + url);
|
||||
//params.put("ip", cmd.getHost());
|
||||
params.put("adminuser", username);
|
||||
params.put("adminpass", password);
|
||||
params.put("url", url);
|
||||
|
||||
Map<String, Object> hostdetails = new HashMap<String, Object>();
|
||||
hostdetails.putAll(params);
|
||||
try {
|
||||
resource.configure(name, hostdetails);
|
||||
} catch (ConfigurationException e) {
|
||||
throw new CloudRuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
final Host host = resourceManager.addHost(zoneId, resource, Host.Type.BackupRecovery, params);
|
||||
if (host != null) {
|
||||
return Transaction.execute(new TransactionCallback<BackupRecoveryProviderVO>() {
|
||||
@Override
|
||||
public BackupRecoveryProviderVO doInTransaction(TransactionStatus status) {
|
||||
BackupRecoveryProviderVO providerVO = new BackupRecoveryProviderVO(host.getId(), name, zoneId, url, providerName);
|
||||
providerVO = backupRecoveryProviderDao.persist(providerVO);
|
||||
|
||||
DetailVO detail = new DetailVO(host.getId(), "providerid", String.valueOf(providerVO.getId()));
|
||||
hostDetailsDao.persist(detail);
|
||||
|
||||
return providerVO;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
throw new CloudRuntimeException("Failed to add the Backup and Recovery provider " + providerName + " - " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteBackupRecoveryProvider(DeleteBackupRecoveryProviderCmd cmd) {
|
||||
Long providerId = cmd.getProviderId();
|
||||
BackupRecoveryProviderVO providerVO = backupRecoveryProviderDao.findById(providerId);
|
||||
if (providerVO == null) {
|
||||
throw new InvalidParameterValueException("Could not find a Backup and Recovery provider with id: " + providerId);
|
||||
}
|
||||
|
||||
HostVO host = hostDao.findById(providerVO.getHostId());
|
||||
|
||||
host.setResourceState(ResourceState.Maintenance);
|
||||
hostDao.update(host.getId(), host);
|
||||
resourceManager.deleteHost(host.getId(), false, false);
|
||||
|
||||
backupRecoveryProviderDao.remove(providerId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BackupRecoveryProviderVO> listBackupRecoveryProviders(ListBackupRecoveryProvidersCmd cmd) {
|
||||
Long zoneId = cmd.getZoneId();
|
||||
String providerName = cmd.getProvider();
|
||||
|
||||
if (zoneId == null) {
|
||||
throw new InvalidParameterException("Must specify a zone id");
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(providerName)) {
|
||||
if (!BackupRecoveryHelper.isProviderSupported(providerName)) {
|
||||
throw new InvalidParameterException("Unsopported provider: " + providerName);
|
||||
}
|
||||
backupRecoveryProviderDao.listByZoneAndProvider(zoneId, providerName);
|
||||
}
|
||||
return backupRecoveryProviderDao.listByZone(zoneId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackupRecoveryProviderResponse createBackupRecoveryProviderResponse(BackupRecoveryProviderVO vo) {
|
||||
HostVO host = hostDao.findById(vo.getHostId());
|
||||
DataCenterVO dc = dataCenterDao.findById(vo.getZoneId());
|
||||
|
||||
BackupRecoveryProviderResponse response = new BackupRecoveryProviderResponse();
|
||||
response.setHostId(host.getUuid());
|
||||
response.setId(vo.getUuid());
|
||||
response.setName(vo.getName());
|
||||
response.setProviderName(vo.getProviderName());
|
||||
response.setZoneId(dc.getUuid());
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackupPolicyResponse createBackupPolicyResponse(BackupPolicyVO policyVO) {
|
||||
BackupRecoveryProviderVO provider = backupRecoveryProviderDao.findById(policyVO.getProviderId());
|
||||
|
||||
BackupPolicyResponse response = new BackupPolicyResponse();
|
||||
response.setId(policyVO.getUuid());
|
||||
response.setPolicyId(policyVO.getPolicyUuid());
|
||||
response.setName(policyVO.getName());
|
||||
response.setProviderId(provider.getUuid());
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getCommands() {
|
||||
final List<Class<?>> cmdList = new ArrayList<Class<?>>();
|
||||
cmdList.add(AddBackupRecoveryProviderCmd.class);
|
||||
cmdList.add(DeleteBackupRecoveryProviderCmd.class);
|
||||
cmdList.add(ListBackupRecoveryProvidersCmd.class);
|
||||
cmdList.add(ListBackupRecoveryPoliciesCmd.class);
|
||||
cmdList.add(ListBackupRecoveryProviderPoliciesCmd.class);
|
||||
cmdList.add(AddBackupRecoveryPolicyCmd.class);
|
||||
return cmdList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigComponentName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigKey<?>[] getConfigKeys() {
|
||||
return new ConfigKey[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BackupRecoveryProviderPolicyResponse> listBackupPolicies(ListBackupRecoveryProviderPoliciesCmd cmd) throws AgentUnavailableException, OperationTimedoutException {
|
||||
Long providerId = cmd.getProviderId();
|
||||
BackupRecoveryProviderVO providerVO = backupRecoveryProviderDao.findById(providerId);
|
||||
if (providerVO == null) {
|
||||
throw new InvalidParameterValueException("Could not find a Backup and Recovery provider with id: " + cmd.getProviderId());
|
||||
}
|
||||
|
||||
if (!BackupRecoveryHelper.isProviderSupported(providerVO.getProviderName())) {
|
||||
throw new InvalidParameterValueException("Provider: " + providerVO.getProviderName() + " is not supported");
|
||||
}
|
||||
|
||||
DataCenterVO zone = dataCenterDao.findById(providerVO.getZoneId());
|
||||
ListBackupPoliciesCommand command = new ListBackupPoliciesCommand(zone.getUuid());
|
||||
ListBackupPoliciesAnswer answer = (ListBackupPoliciesAnswer) agentManager.send(providerVO.getHostId(), command);
|
||||
|
||||
if (answer != null && answer.getResult()) {
|
||||
return createBackupRecoveryProviderPoliciesResponse(answer.getPolicies());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<BackupRecoveryProviderPolicyResponse> createBackupRecoveryProviderPoliciesResponse(List<BackupPolicyTO> policies) {
|
||||
List<BackupRecoveryProviderPolicyResponse> list = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(policies)) {
|
||||
for (BackupPolicyTO policy : policies) {
|
||||
BackupRecoveryProviderPolicyResponse p = new BackupRecoveryProviderPolicyResponse();
|
||||
p.setName(policy.getName());
|
||||
p.setPolicyId(policy.getId());
|
||||
p.setDescription(policy.getDescription());
|
||||
list.add(p);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BackupPolicyVO> listBackupPolicies(ListBackupRecoveryPoliciesCmd cmd) {
|
||||
return backupPoliciesDao.listByProvider(cmd.getProviderId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackupPolicyVO addBackupPolicy(AddBackupRecoveryPolicyCmd cmd) throws AgentUnavailableException, OperationTimedoutException {
|
||||
String policyId = cmd.getPolicyId();
|
||||
Long providerId = cmd.getProviderId();
|
||||
String name = cmd.getPolicyName();
|
||||
|
||||
BackupRecoveryProviderVO provider = backupRecoveryProviderDao.findById(providerId);
|
||||
if (provider == null) {
|
||||
throw new InvalidParameterValueException("Could not find a Backup and Recovery provider with id: " + providerId);
|
||||
}
|
||||
|
||||
CheckBackupPolicyCommand command = new CheckBackupPolicyCommand(policyId);
|
||||
CheckBackupPolicyAnswer answer = (CheckBackupPolicyAnswer) agentManager.send(provider.getHostId(), command);
|
||||
if (answer == null || !answer.getResult()) {
|
||||
throw new InvalidParameterValueException("Could not find a backup policy with id: " + policyId + " on the provider");
|
||||
}
|
||||
BackupPolicyVO policy = new BackupPolicyVO(providerId, name, policyId);
|
||||
return backupPoliciesDao.persist(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean assignVMToBackupPolicy(AssignBackupPolicyCmd cmd) throws AgentUnavailableException, OperationTimedoutException {
|
||||
String policyId = cmd.getPolicyId();
|
||||
Long virtualMachineId = cmd.getVirtualMachineId();
|
||||
VMInstanceVO vm = vmInstanceDao.findById(virtualMachineId);
|
||||
BackupPolicyVO policy = backupPoliciesDao.findByUuid(policyId);
|
||||
BackupRecoveryProviderVO provider = backupRecoveryProviderDao.findById(policy.getProviderId());
|
||||
|
||||
AssignVMToBackupPolicyCommand command = new AssignVMToBackupPolicyCommand(virtualMachineId, vm.getUuid(), policyId);
|
||||
AssignVMToBackupPolicyAnswer answer = (AssignVMToBackupPolicyAnswer) agentManager.send(provider.getHostId(), command);
|
||||
return answer != null && answer.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreVMFromBackup() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreAndAttachVolumeToVM() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,155 +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.backuprecovery.resource;
|
||||
|
||||
import com.cloud.agent.IAgentControl;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.StartupBackupRecoveryProviderCommand;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.Map;
|
||||
|
||||
public class BackupRecoveryResource implements ServerResource {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(BackupRecoveryResource.class);
|
||||
private String name;
|
||||
private String zoneId;
|
||||
private String guid;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
if (MapUtils.isNotEmpty(params)) {
|
||||
this.name = (String) params.get("name");
|
||||
if (this.name == null) {
|
||||
throw new ConfigurationException("Unable to find name");
|
||||
}
|
||||
|
||||
zoneId = (String) params.get("zoneId");
|
||||
if (zoneId == null) {
|
||||
throw new ConfigurationException("Unable to find zone");
|
||||
}
|
||||
|
||||
guid = (String) params.get("guid");
|
||||
if (guid == null) {
|
||||
throw new ConfigurationException("Unable to find guid");
|
||||
}
|
||||
|
||||
/*final String ip = (String) params.get("ip");
|
||||
if (ip == null) {
|
||||
throw new ConfigurationException("Unable to find IP");
|
||||
}*/
|
||||
|
||||
final String adminuser = (String) params.get("adminuser");
|
||||
if (adminuser == null) {
|
||||
throw new ConfigurationException("Unable to find admin username");
|
||||
}
|
||||
|
||||
final String adminpass = (String) params.get("adminpass");
|
||||
if (adminpass == null) {
|
||||
throw new ConfigurationException("Unable to find admin password");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Host.Type getType() {
|
||||
return Host.Type.BackupRecovery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
final StartupBackupRecoveryProviderCommand sc = new StartupBackupRecoveryProviderCommand();
|
||||
sc.setGuid(guid);
|
||||
sc.setName(name);
|
||||
sc.setDataCenter(zoneId);
|
||||
sc.setPod(null);
|
||||
sc.setPrivateIpAddress("");
|
||||
sc.setStorageIpAddress("");
|
||||
sc.setVersion(BackupRecoveryResource.class.getPackage().getImplementationVersion());
|
||||
return new StartupCommand[] { sc };
|
||||
}
|
||||
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return new PingCommand(getType(), id);
|
||||
}
|
||||
|
||||
public Answer executeRequest(Command cmd) {
|
||||
s_logger.debug("Received Command: " + cmd.toString());
|
||||
Answer answer = new Answer(cmd, true, "response");
|
||||
s_logger.debug("Replying with: " + answer.toString());
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAgentControl getAgentControl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAgentControl(IAgentControl agentControl) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigParams(Map<String, Object> params) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConfigParams() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRunLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRunLevel(int level) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,14 +17,13 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.agent.api;
|
||||
package org.apache.cloudstack.framework.br;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
public interface BRPolicy {
|
||||
|
||||
public class ImportBackupPoliciesCommand extends Command {
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
long getId();
|
||||
String getUuid();
|
||||
String getPolicyUuid();
|
||||
String getName();
|
||||
long getProviderId();
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
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<BRPolicy> listBRPolicies(String providerId);
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.apache.cloudstack.framework.br;
|
||||
|
||||
public interface BRProvider {
|
||||
long getId();
|
||||
String getUuid();
|
||||
String getName();
|
||||
String getUrl();
|
||||
long getZoneId();
|
||||
String getProviderName();
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
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<BRProvider> listBRProviders();
|
||||
|
||||
/**
|
||||
* Delete existing Backup and Recovery provider
|
||||
*/
|
||||
boolean deleteBRProvider(String providerId);
|
||||
}
|
||||
|
|
@ -15,11 +15,11 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.framework.backuprecovery.element;
|
||||
package org.apache.cloudstack.framework.br;
|
||||
|
||||
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
|
||||
/**
|
||||
* Backup and Recovery Services
|
||||
*/
|
||||
public interface BRService extends BRProviderService, BRPolicyService {
|
||||
|
||||
public interface BackupRecoveryElementService {
|
||||
|
||||
BackupRecoveryResource createNewResource();
|
||||
}
|
||||
|
|
@ -1,40 +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.backuprecovery.element;
|
||||
|
||||
import org.apache.cloudstack.backuprecovery.resource.DummyBackupRecoveryResource;
|
||||
import org.apache.cloudstack.framework.backuprecovery.element.BackupRecoveryElement;
|
||||
import org.apache.cloudstack.framework.backuprecovery.helper.BackupRecoveryHelper;
|
||||
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.Map;
|
||||
|
||||
public class DummyBackupRecoveryElement extends BackupRecoveryElement {
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
BackupRecoveryHelper.addProvider("Dummy", this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackupRecoveryResource createNewResource() {
|
||||
return new DummyBackupRecoveryResource();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +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.backuprecovery.resource;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyAnswer;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyCommand;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyAnswer;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyCommand;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesAnswer;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesCommand;
|
||||
import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO;
|
||||
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DummyBackupRecoveryResource extends BackupRecoveryResource {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(DummyBackupRecoveryResource.class);
|
||||
|
||||
private BackupPolicyTO policy1 = new BackupPolicyTO("aaaa-aaaa", "Policy A", "Gold policy");
|
||||
private BackupPolicyTO policy2 = new BackupPolicyTO("bbbb-bbbb", "Policy B", "Silver policy");
|
||||
|
||||
private List<BackupPolicyTO> policies = Arrays.asList(policy1, policy2);
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
|
||||
s_logger.debug("Received Command: " + cmd.toString());
|
||||
Answer answer = new Answer(cmd, true, "response");
|
||||
if (cmd instanceof ListBackupPoliciesCommand) {
|
||||
answer = execute((ListBackupPoliciesCommand) cmd);
|
||||
} else if (cmd instanceof CheckBackupPolicyCommand) {
|
||||
answer = execute((CheckBackupPolicyCommand) cmd);
|
||||
} else if (cmd instanceof AssignVMToBackupPolicyCommand) {
|
||||
answer = execute((AssignVMToBackupPolicyCommand) cmd);
|
||||
}
|
||||
s_logger.debug("Replying with: " + answer.toString());
|
||||
return answer;
|
||||
}
|
||||
|
||||
private Answer execute(AssignVMToBackupPolicyCommand cmd) {
|
||||
s_logger.debug("Assigning VM " + cmd.getVmUuid() + " to Backup policy: " + cmd.getBackupPolicyUuid());
|
||||
return new AssignVMToBackupPolicyAnswer(true);
|
||||
}
|
||||
|
||||
private Answer execute(CheckBackupPolicyCommand cmd) {
|
||||
s_logger.debug("Checking if backup policy " + cmd.getPolicyUuid() + " exists");
|
||||
boolean result = false;
|
||||
String policyUuid = cmd.getPolicyUuid();
|
||||
for (BackupPolicyTO policy: policies) {
|
||||
if (policy.getId().equals(policyUuid)) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new CheckBackupPolicyAnswer(result);
|
||||
}
|
||||
|
||||
private Answer execute(ListBackupPoliciesCommand cmd) {
|
||||
s_logger.debug("Listing existing backup policies");
|
||||
return new ListBackupPoliciesAnswer(true, policies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
return super.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "DummyBackupRecoveryProvider";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
// 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<BRPolicy> 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() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,8 +21,7 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
|
||||
>
|
||||
|
||||
<bean id="dummyBackupRecoveryElement" class="org.apache.cloudstack.backuprecovery.element.DummyBackupRecoveryElement">
|
||||
<property name="name" value="DummyBackupRecoveryElement" />
|
||||
<bean id="dummyBackupRecoveryDriver" class="org.apache.cloudstack.br.DummyBRProvider">
|
||||
<property name="name" value="Dummy" />
|
||||
</bean>
|
||||
</beans>
|
||||
|
|
@ -151,6 +151,11 @@
|
|||
<artifactId>opensaml</artifactId>
|
||||
<version>${cs.opensaml.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-framework-backup-and-recovery</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,260 @@
|
|||
// 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<BRProviderDriver> brProviders = new ArrayList<>();
|
||||
private Map<String, BRProviderDriver> brProvidersMap = new HashMap<>();
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(BRManagerImpl.class);
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> 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<BRProviderDriver> getBackupRecoveryProviders() {
|
||||
return brProviders;
|
||||
}
|
||||
|
||||
public void setBackupRecoveryProviders(List<BRProviderDriver> 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<BRProviderDetailVO> 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<BRProvider> listBRProviders() {
|
||||
return new ArrayList<BRProvider>(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<BRPolicy> listBRPolicies(String providerId) {
|
||||
BRProviderVO provider = brProviderDao.findByUuid(providerId);
|
||||
return new ArrayList<BRPolicy>(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<Class<?>> getCommands() {
|
||||
final List<Class<?>> cmdList = new ArrayList<Class<?>>();
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
|
@ -298,4 +298,8 @@
|
|||
<bean id="indirectAgentLBService" class="org.apache.cloudstack.agent.lb.IndirectAgentLBServiceImpl" />
|
||||
|
||||
<bean id="directDownloadManager" class="org.apache.cloudstack.direct.download.DirectDownloadManagerImpl" />
|
||||
|
||||
<bean id="backupRecoveryManagerImpl" class="org.apache.cloudstack.br.BRManagerImpl" >
|
||||
<property name="backupRecoveryProviders" value="#{backupRecoveryRegistry.registered}" />
|
||||
</bean>
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ known_categories = {
|
|||
'listElastistorInterface': 'Misc',
|
||||
'cloudian': 'Cloudian',
|
||||
'Sioc' : 'Sioc',
|
||||
'BackupRecovery' : 'BackupRecovery'
|
||||
'BR' : 'BackupRecovery'
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue