Backup and Recovery Framework and DummyProvider

This commit is contained in:
nvazquez 2018-05-02 22:41:11 -03:00
parent ca17b6a126
commit fcd39839f8
54 changed files with 2978 additions and 3 deletions

View File

@ -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);
ExternalDhcp(false), SecondaryStorageVM(true), LocalSecondaryStorage(false), L2Networking(false), BackupRecovery(true);
boolean _virtual;
private Type(boolean virtual) {

View File

@ -719,6 +719,11 @@ public class ApiConstants {
public static final String LAST_ANNOTATED = "lastannotated";
public static final String LDAP_DOMAIN = "ldapdomain";
// Backup and Recovery
public static final String BACKUP_PROVIDER_ID = "backupproviderid";
public static final String BACKUP_POLICY_ID = "backuppolicyid";
public static final String BACKUP_POLICY_NAME = "backuppolicyname";
public enum HostDetails {
all, capacity, events, stats, min;
}

View File

@ -473,6 +473,16 @@
<artifactId>cloud-plugin-integrations-prometheus-exporter</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.cloudstack</groupId>
<artifactId>cloud-plugin-backup-and-recovery-dummy</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -323,4 +323,8 @@
class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry">
</bean>
<bean id="backupRecoveryRegistry"
class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry">
</bean>
</beans>

View File

@ -32,4 +32,32 @@ ALTER TABLE `vlan` CHANGE `description` `ip4_range` varchar(255);
-- We are only adding the permission to the default rules. Any custom rule must be configured by the root admin.
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 2, 'moveNetworkAclItem', 'ALLOW', 100) ON DUPLICATE KEY UPDATE rule=rule;
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 3, 'moveNetworkAclItem', 'ALLOW', 302) ON DUPLICATE KEY UPDATE rule=rule;
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 4, 'moveNetworkAclItem', 'ALLOW', 260) ON DUPLICATE KEY UPDATE rule=rule;
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 4, 'moveNetworkAclItem', 'ALLOW', 260) ON DUPLICATE KEY UPDATE rule=rule;
-- Backup and Recovery
CREATE TABLE IF NOT EXISTS `cloud`.`backup_and_recovery_providers` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`uuid` varchar(40),
`name` varchar(255) COMMENT 'name for the backup and recovery provider',
`url` varchar(255) DEFAULT NULL COMMENT 'the url of the backup and recovery provider',
`zone_id` bigint unsigned NOT NULL COMMENT 'foreign key to zone id',
`host_id` bigint(20) unsigned NOT NULL COMMENT 'host id coresponding to the backup and recovery provider',
`provider` varchar(255) DEFAULT NULL COMMENT 'the backup and recovery provider',
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`),
KEY `fk_backup_and_recovery_providers__host_id` (`host_id`),
CONSTRAINT `fk_backup_and_recovery_providers__host_id` FOREIGN KEY (`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_backup_and_recovery_providers__zone_id` FOREIGN KEY (`zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `cloud`.`backup_policies` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`uuid` varchar(40) NOT NULL,
`provider_id` bigint(20) unsigned NOT NULL COMMENT 'backup and recovery provider id',
`name` varchar(255) NOT NULL COMMENT 'backup policy name',
`policy_uuid` varchar(40) NOT NULL COMMENT 'backup policy ID on provider side',
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`),
CONSTRAINT `fk_backup_polocies__provider_id` FOREIGN KEY (`provider_id`) REFERENCES `backup_and_recovery_providers` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,60 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-framework-backup-and-recovery</artifactId>
<name>Apache CloudStack Framework - Backup and Recovery</name>
<parent>
<artifactId>cloudstack-framework</artifactId>
<groupId>org.apache.cloudstack</groupId>
<version>4.12.0.0-SNAPSHOT</version>
<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>

View File

@ -0,0 +1,28 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery;
import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.framework.config.Configurable;
/**
* Backup and Recover Manager Interface
*/
public interface BackupRecoveryManager extends BackupRecoveryService, BackupRecoveryProvider, Configurable, PluggableService {
}

View File

@ -0,0 +1,60 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.utils.component.Adapter;
import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryPolicyCmd;
import org.apache.cloudstack.framework.backuprecovery.api.AssignBackupPolicyCmd;
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryPoliciesCmd;
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProviderPoliciesCmd;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
import java.util.List;
/**
* Backup and Recovery Provider
*/
public interface BackupRecoveryProvider extends Adapter {
/**
* List existing Backup Policies on the provider
*/
List<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();
}

View File

@ -0,0 +1,59 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery;
import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryProviderCmd;
import org.apache.cloudstack.framework.backuprecovery.api.DeleteBackupRecoveryProviderCmd;
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProvidersCmd;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
public interface BackupRecoveryService {
/**
* Add a new Backup and Recovery provider
*/
BackupRecoveryProviderVO addBackupRecoveryProvider(AddBackupRecoveryProviderCmd cmd) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException;
/**
* Delete existing Backup and Recovery provider
*/
boolean deleteBackupRecoveryProvider(DeleteBackupRecoveryProviderCmd cmd);
/**
* List existing Backup and Recovery providers
* @param cmd
* @return
*/
List<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);
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Answer;
public class AssignVMToBackupPolicyAnswer extends Answer {
public AssignVMToBackupPolicyAnswer(final boolean result) {
super(null);
this.result = result;
}
}

View File

@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Command;
public class AssignVMToBackupPolicyCommand extends Command {
private long vmId;
private String vmUuid;
private String backupPolicyUuid;
public AssignVMToBackupPolicyCommand(final long vmId, final String vmUuid, final String backupPolicyUuid) {
this.vmId = vmId;
this.vmUuid = vmUuid;
this.backupPolicyUuid = backupPolicyUuid;
}
public long getVmId() {
return vmId;
}
public String getVmUuid() {
return vmUuid;
}
public String getBackupPolicyUuid() {
return backupPolicyUuid;
}
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Answer;
public class CheckBackupPolicyAnswer extends Answer {
public CheckBackupPolicyAnswer(final boolean result) {
super(null);
this.result = result;
}
}

View File

@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Command;
public class CheckBackupPolicyCommand extends Command {
private String policyUuid;
public CheckBackupPolicyCommand(final String policyUuid) {
this.policyUuid = policyUuid;
}
public String getPolicyUuid() {
return policyUuid;
}
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Answer;
import java.util.List;
public class ImportBackupPoliciesAnswer extends Answer {
private List<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;
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Command;
public class ImportBackupPoliciesCommand extends Command {
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Answer;
import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO;
import java.util.List;
public class ListBackupPoliciesAnswer extends Answer {
private List<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;
}
}

View File

@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Command;
public class ListBackupPoliciesCommand extends Command {
private String zoneUuid;
@Override
public boolean executeInSequence() {
return false;
}
public ListBackupPoliciesCommand(String zoneUuid) {
this.zoneUuid = zoneUuid;
}
public String getZoneUuid() {
return zoneUuid;
}
}

View File

@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Answer;
import java.util.List;
public class ListBackupsAnswer extends Answer {
private List<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;
}
}

View File

@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Command;
public class ListBackupsCommand extends Command {
private Long vmId;
public ListBackupsCommand(final Long vmId) {
this.vmId = vmId;
}
public Long getVmId() {
return vmId;
}
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Answer;
public class RestoreVMFromBackupAnswer extends Answer {
public RestoreVMFromBackupAnswer(final boolean result) {
super(null);
this.result = result;
}
}

View File

@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.Command;
public class RestoreVMFromBackupCommand extends Command {
private long vmId;
private String vmUuid;
private long backupId;
private String backupUuid;
public RestoreVMFromBackupCommand(final long vmId, final String vmUuid, final long backupId, final String backupUuid) {
this.vmId = vmId;
this.vmUuid = vmUuid;
this.backupId = backupId;
this.backupUuid = backupUuid;
}
public long getVmId() {
return vmId;
}
public String getVmUuid() {
return vmUuid;
}
public long getBackupId() {
return backupId;
}
public String getBackupUuid() {
return backupUuid;
}
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -0,0 +1,28 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.agent.api;
import com.cloud.agent.api.StartupCommand;
import com.cloud.host.Host;
public class StartupBackupRecoveryProviderCommand extends StartupCommand {
public StartupBackupRecoveryProviderCommand() {
super(Host.Type.BackupRecovery);
}
}

View File

@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.agent.api.to;
import java.io.Serializable;
public class BackupPolicyTO implements Serializable {
private String name;
private String id;
private String description;
public BackupPolicyTO(final String id, final String name, final String desc) {
this.id = id;
this.name = name;
this.description = desc;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
public String getDescription() {
return description;
}
}

View File

@ -0,0 +1,96 @@
package org.apache.cloudstack.framework.backuprecovery.api;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
import javax.inject.Inject;
@APICommand(name = AddBackupRecoveryPolicyCmd.APINAME,
description = "Adds a Backup policy",
responseObject = BackupPolicyResponse.class, since = "4.12.0",
authorized = {RoleType.Admin})
public class AddBackupRecoveryPolicyCmd extends BaseCmd {
public static final String APINAME = "addBackupRecoveryPolicy";
@Inject
BackupRecoveryManager backupRecoveryManager;
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the policy")
private String policyName;
@Parameter(name = ApiConstants.BACKUP_POLICY_ID,
type = CommandType.STRING,
entityType = BackupRecoveryProviderResponse.class,
required = true,
description = "Backup Recovery Provider ID")
private String policyId;
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
type = BaseCmd.CommandType.UUID,
entityType = BackupRecoveryProviderResponse.class,
required = true,
description = "Backup Recovery Provider ID")
private Long providerId;
public String getPolicyName() {
return policyName;
}
public String getPolicyId() {
return policyId;
}
public Long getProviderId() {
return providerId;
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
BackupPolicyVO policyVO = backupRecoveryManager.addBackupPolicy(this);
if (policyVO != null) {
BackupPolicyResponse response = backupRecoveryManager.createBackupPolicyResponse(policyVO);
response.setObjectName("backuppolicy");
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add a Backup policy");
}
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
} catch (CloudRuntimeException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (OperationTimedoutException e) {
e.printStackTrace();
}
}
@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
}

View File

@ -0,0 +1,135 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.api;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import java.lang.reflect.InvocationTargetException;
@APICommand(name = AddBackupRecoveryProviderCmd.APINAME,
description = "Adds a Backup and Recovery provider on a zone",
responseObject = BackupRecoveryProviderResponse.class, since = "4.12.0",
authorized = {RoleType.Admin})
public class AddBackupRecoveryProviderCmd extends BaseCmd {
public static final String APINAME = "addBackupRecoveryProvider";
private static final Logger s_logger = Logger.getLogger(AddBackupRecoveryProviderCmd.class);
@Inject
BackupRecoveryManager backupRecoveryManager;
@Parameter(name=ApiConstants.ZONE_ID, type=BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
required=true, description="the ID of the zone you wish to register the Backup and Recovery provider to.")
private Long zoneId;
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the Backup and Recovery provider")
private String name;
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, length = 2048, description = "the URL of the Backup and Recovery provider portal")
private String url;
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "the username for the Backup and Recovery provider")
private String username;
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "the password for the Backup and Recovery provider")
private String password;
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true, description = "the Backup and Recovery provider type")
private String provider;
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
BackupRecoveryProviderVO providerVO = backupRecoveryManager.addBackupRecoveryProvider(this);
if (providerVO != null) {
BackupRecoveryProviderResponse response = backupRecoveryManager.createBackupRecoveryProviderResponse(providerVO);
response.setObjectName("backuprecoveryprovider");
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add a Backup and Recovery Provider");
}
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
} catch (CloudRuntimeException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
public Long getZoneId() {
return zoneId;
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getProvider() {
return provider;
}
}

View File

@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.api;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import javax.inject.Inject;
@APICommand(name = AssignBackupPolicyCmd.APINAME,
description = "Assigns a VM to an existing backup policy",
responseObject = SuccessResponse.class, since = "4.12.0")
public class AssignBackupPolicyCmd extends BaseCmd {
public static final String APINAME = "assignBackupPolicy";
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
type = CommandType.UUID,
entityType = UserVmResponse.class,
required = true,
description = "id of the VM to be moved")
private Long virtualMachineId;
@Parameter(name = ApiConstants.BACKUP_POLICY_ID,
type = CommandType.STRING,
entityType = BackupRecoveryProviderResponse.class,
required = true,
description = "Backup Recovery Provider ID")
private String policyId;
public Long getVirtualMachineId() {
return virtualMachineId;
}
public String getPolicyId() {
return policyId;
}
@Inject
BackupRecoveryManager backupRecoveryManager;
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
boolean result = backupRecoveryManager.assignVMToBackupPolicy(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign VM to backup policy");
}
} catch (Exception e) {
}
}
@Override
public String getCommandName() {
return AssignBackupPolicyCmd.APINAME + BaseCmd.RESPONSE_SUFFIX;
}
@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
}

View File

@ -0,0 +1,90 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.api;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import javax.inject.Inject;
@APICommand(name = DeleteBackupRecoveryProviderCmd.APINAME,
description = "Deletes a Backup and Recovery provider",
responseObject = SuccessResponse.class, since = "4.12.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
authorized = {RoleType.Admin})
public class DeleteBackupRecoveryProviderCmd extends BaseCmd {
public static final String APINAME = "deleteBackupRecoveryProvider";
@Inject
BackupRecoveryManager backupRecoveryManager;
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
type = CommandType.UUID,
entityType = BackupRecoveryProviderResponse.class,
required = true,
description = "Backup Recovery Provider ID")
private Long providerId;
public Long getProviderId() {
return providerId;
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
boolean result = backupRecoveryManager.deleteBackupRecoveryProvider(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Backup and Recovery Provider");
}
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
} catch (CloudRuntimeException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
}

View File

@ -0,0 +1,89 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.api;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
import org.apache.commons.collections.CollectionUtils;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@APICommand(name = ListBackupRecoveryPoliciesCmd.APINAME,
description = "Lists mapped Backup policies",
responseObject = BackupPolicyResponse.class, since = "4.12.0",
authorized = {RoleType.Admin})
public class ListBackupRecoveryPoliciesCmd extends BaseListCmd {
public static final String APINAME = "listBackupRecoveryPolicies";
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
type = BaseCmd.CommandType.UUID,
entityType = BackupRecoveryProviderResponse.class,
required = true,
description = "Backup Recovery Provider ID")
private Long providerId;
public long getProviderId() {
return providerId;
}
@Inject
BackupRecoveryManager backupRecoveryManager;
@Override
public void execute() throws ServerApiException, ConcurrentOperationException {
try {
ListResponse<BackupPolicyResponse> response = new ListResponse<BackupPolicyResponse>();
List<BackupPolicyResponse> responses = new ArrayList<>();
List<BackupPolicyVO> policies = backupRecoveryManager.listBackupPolicies(this);
if (CollectionUtils.isNotEmpty(policies)) {
for (BackupPolicyVO policy : policies) {
BackupPolicyResponse p = backupRecoveryManager.createBackupPolicyResponse(policy);
responses.add(p);
}
}
response.setResponses(responses, responses.size());
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
} catch (CloudRuntimeException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
}

View File

@ -0,0 +1,85 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.api;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import javax.inject.Inject;
import java.util.List;
@APICommand(name = ListBackupRecoveryProviderPoliciesCmd.APINAME,
description = "Lists Backup policies existing on the Backup and Recovery provider side",
responseObject = BackupRecoveryProviderPolicyResponse.class, since = "4.12.0",
authorized = {RoleType.Admin})
public class ListBackupRecoveryProviderPoliciesCmd extends BaseListCmd {
public static final String APINAME = "listBackupRecoveryProviderPolicies";
@Inject
BackupRecoveryManager backupRecoveryManager;
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
type = BaseCmd.CommandType.UUID,
entityType = BackupRecoveryProviderResponse.class,
required = true,
description = "Backup Recovery Provider ID")
private Long providerId;
public Long getProviderId() {
return providerId;
}
@Override
public void execute() throws ResourceUnavailableException, ServerApiException, ConcurrentOperationException {
try {
ListResponse<BackupRecoveryProviderPolicyResponse> response = new ListResponse<BackupRecoveryProviderPolicyResponse>();
List<BackupRecoveryProviderPolicyResponse> policies = backupRecoveryManager.listBackupPolicies(this);
if (policies == null) {
throw new CloudRuntimeException("Error while retrieving backup provider policies");
}
response.setResponses(policies, policies.size());
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
} catch (CloudRuntimeException | OperationTimedoutException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
}

View File

@ -0,0 +1,97 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.api;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
import org.apache.commons.collections.CollectionUtils;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@APICommand(name = ListBackupRecoveryProvidersCmd.APINAME,
description = "Lists Backup and Recovery providers",
responseObject = BackupRecoveryProviderResponse.class, since = "4.12.0",
authorized = {RoleType.Admin})
public class ListBackupRecoveryProvidersCmd extends BaseListCmd {
public static final String APINAME = "listBackupRecoveryProviders";
@Inject
BackupRecoveryManager backupRecoveryManager;
@Parameter(name=ApiConstants.ZONE_ID, type=BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
description="the ID of the zone")
private Long zoneId;
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, entityType = BackupRecoveryProviderResponse.class,
description = "the Backup and Recovery provider type")
private String provider;
public Long getZoneId() {
return zoneId;
}
public String getProvider() {
return provider;
}
@Override
public void execute() throws ServerApiException, ConcurrentOperationException {
try {
List<BackupRecoveryProviderVO> providers = backupRecoveryManager.listBackupRecoveryProviders(this);
ListResponse<BackupRecoveryProviderResponse> response = new ListResponse<BackupRecoveryProviderResponse>();
List<BackupRecoveryProviderResponse> providersResponse = new ArrayList<BackupRecoveryProviderResponse>();
if (CollectionUtils.isNotEmpty(providers)) {
for (BackupRecoveryProviderVO providerVO : providers) {
BackupRecoveryProviderResponse providerResponse = backupRecoveryManager.createBackupRecoveryProviderResponse(providerVO);
providersResponse.add(providerResponse);
}
}
response.setResponses(providersResponse, providersResponse.size());
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
} catch (CloudRuntimeException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
}

View File

@ -0,0 +1,61 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.api.response;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
@EntityReference(value = BackupPolicyVO.class)
public class BackupPolicyResponse extends BaseResponse {
@SerializedName(ApiConstants.ID)
@Param(description = "internal id of the Backup policy")
private String id;
@SerializedName(ApiConstants.BACKUP_POLICY_ID)
@Param(description = "policy id on the provider side")
private String policyId;
@SerializedName(ApiConstants.BACKUP_PROVIDER_ID)
@Param(description = "id of the Backup and Recovery provider")
private String providerId;
@SerializedName(ApiConstants.BACKUP_POLICY_NAME)
@Param(description = "internal name for the backup policy")
private String name;
public void setId(String id) {
this.id = id;
}
public void setPolicyId(String policyId) {
this.policyId = policyId;
}
public void setProviderId(String providerId) {
this.providerId = providerId;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,53 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.api.response;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
/**
* Response for a Backup Policy on the provider
*/
public class BackupRecoveryProviderPolicyResponse extends BaseResponse {
@SerializedName(ApiConstants.BACKUP_POLICY_ID)
@Param(description = "policy id on the provider side")
private String policyId;
@SerializedName(ApiConstants.BACKUP_POLICY_NAME)
@Param(description = "name for the backup policy on the provider side")
private String name;
@SerializedName(ApiConstants.DESCRIPTION)
@Param(description = "description for the backup policy on the provider side")
private String description;
public void setPolicyId(String policyId) {
this.policyId = policyId;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String desc) {
this.description = desc;
}
}

View File

@ -0,0 +1,69 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.api.response;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
@EntityReference(value = BackupRecoveryProviderVO.class)
public class BackupRecoveryProviderResponse extends BaseResponse {
@SerializedName(ApiConstants.BACKUP_PROVIDER_ID)
@Param(description = "id of the Backup and Recovery provider")
private String id;
@SerializedName(ApiConstants.PROVIDER)
@Param(description = "name of the provider")
private String providerName;
@SerializedName(ApiConstants.NAME)
@Param(description = "internal name for the Backup and Recovery provider")
private String name;
@SerializedName(ApiConstants.ZONE_ID)
@Param(description = "id of the zone")
private String zoneId;
@SerializedName(ApiConstants.HOST_ID)
@Param(description = "id of the host")
private String hostId;
public void setId(String id) {
this.id = id;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public void setName(String name) {
this.name = name;
}
public void setZoneId(String zoneId) {
this.zoneId = zoneId;
}
public void setHostId(String hostId) {
this.hostId = hostId;
}
}

View File

@ -0,0 +1,28 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.dao;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
import java.util.List;
public interface BackupPoliciesDao extends GenericDao<BackupPolicyVO, Long> {
List<BackupPolicyVO> listByProvider(long providerId);
}

View File

@ -0,0 +1,28 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.dao;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.framework.backuprecovery.impl.BackupRecoveryProviderVO;
import java.util.List;
public interface BackupRecoveryProviderDao extends GenericDao<BackupRecoveryProviderVO, Long> {
List<BackupRecoveryProviderVO> listByZone(long zoneId);
List<BackupRecoveryProviderVO> listByZoneAndProvider(long zoneId, String provider);
}

View File

@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.backuprecovery.element;
import com.cloud.agent.api.StartupCommand;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceStateAdapter;
import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException;
import com.cloud.utils.component.AdapterBase;
import org.apache.cloudstack.framework.backuprecovery.agent.api.StartupBackupRecoveryProviderCommand;
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import java.util.List;
import java.util.Map;
/**
* Backup and Recovery Element class.
* To register a Backup and Recovery element, just extend this class
*/
public class BackupRecoveryElement extends AdapterBase implements ResourceStateAdapter, BackupRecoveryElementService {
@Inject
ResourceManager resourceManager;
@Override
public boolean configure(String name, Map<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();
}
}

View File

@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.element;
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
public interface BackupRecoveryElementService {
BackupRecoveryResource createNewResource();
}

View File

@ -0,0 +1,49 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.helper;
import org.apache.cloudstack.framework.backuprecovery.element.BackupRecoveryElement;
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
import java.util.HashMap;
import java.util.Map;
public class BackupRecoveryHelper {
/**
* Backup and Recovery Providers Helper
*/
private static Map<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;
}
}

View File

@ -0,0 +1,50 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.impl;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import org.apache.cloudstack.framework.backuprecovery.dao.BackupPoliciesDao;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.List;
@Component
public class BackupPoliciesDaoImpl extends GenericDaoBase<BackupPolicyVO, Long> implements BackupPoliciesDao {
protected SearchBuilder<BackupPolicyVO> backupPoliciesSearch;
public BackupPoliciesDaoImpl() {
}
@PostConstruct
protected void init() {
backupPoliciesSearch = createSearchBuilder();
backupPoliciesSearch.and("provider", backupPoliciesSearch.entity().getProviderId(), SearchCriteria.Op.EQ);
backupPoliciesSearch.done();
}
@Override
public List<BackupPolicyVO> listByProvider(long providerId) {
SearchCriteria<BackupPolicyVO> sc = backupPoliciesSearch.create();
sc.setParameters("provider", providerId);
return listBy(sc);
}
}

View File

@ -0,0 +1,103 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.impl;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.UUID;
@Entity
@Table(name = "backup_policies")
public class BackupPolicyVO implements InternalIdentity, Identity {
public BackupPolicyVO() {
this.uuid = UUID.randomUUID().toString();
}
public BackupPolicyVO(final long providerId, final String name, final String policyUuid) {
this();
this.providerId = providerId;
this.name = name;
this.policyUuid = policyUuid;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "uuid")
private String uuid;
@Column(name = "provider_id")
private long providerId;
@Column(name = "name")
private String name;
@Column(name = "policy_uuid")
private String policyUuid;
@Override
public String getUuid() {
return null;
}
@Override
public long getId() {
return 0;
}
public void setId(long id) {
this.id = id;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPolicyUuid() {
return policyUuid;
}
public void setPolicyUuid(String policyUuid) {
this.policyUuid = policyUuid;
}
public long getProviderId() {
return providerId;
}
public void setProviderId(long providerId) {
this.providerId = providerId;
}
}

View File

@ -0,0 +1,323 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.impl;
import com.cloud.agent.AgentManager;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.DetailVO;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceState;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionCallback;
import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.dao.VMInstanceDao;
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyAnswer;
import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyCommand;
import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyAnswer;
import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyCommand;
import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesAnswer;
import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesCommand;
import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO;
import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryPolicyCmd;
import org.apache.cloudstack.framework.backuprecovery.api.AddBackupRecoveryProviderCmd;
import org.apache.cloudstack.framework.backuprecovery.api.AssignBackupPolicyCmd;
import org.apache.cloudstack.framework.backuprecovery.api.DeleteBackupRecoveryProviderCmd;
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryPoliciesCmd;
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProviderPoliciesCmd;
import org.apache.cloudstack.framework.backuprecovery.api.ListBackupRecoveryProvidersCmd;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderPolicyResponse;
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
import org.apache.cloudstack.framework.backuprecovery.dao.BackupPoliciesDao;
import org.apache.cloudstack.framework.backuprecovery.dao.BackupRecoveryProviderDao;
import org.apache.cloudstack.framework.backuprecovery.helper.BackupRecoveryHelper;
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import java.lang.reflect.InvocationTargetException;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.ArrayList;
public class BackupRecoveryManagerImpl extends ManagerBase implements BackupRecoveryManager {
@Inject
BackupRecoveryProviderDao backupRecoveryProviderDao;
@Inject
HostDetailsDao hostDetailsDao;
@Inject
ResourceManager resourceManager;
@Inject
HostDao hostDao;
@Inject
DataCenterDao dataCenterDao;
@Inject
BackupPoliciesDao backupPoliciesDao;
@Inject
AgentManager agentManager;
@Inject
VMInstanceDao vmInstanceDao;
private static final Logger s_logger = Logger.getLogger(BackupRecoveryManagerImpl.class);
@Override
public boolean configure(String name, Map<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() {
}
}

View File

@ -0,0 +1,58 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.impl;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import org.apache.cloudstack.framework.backuprecovery.dao.BackupRecoveryProviderDao;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.List;
@Component
public class BackupRecoveryProviderDaoImpl extends GenericDaoBase<BackupRecoveryProviderVO, Long> implements BackupRecoveryProviderDao {
protected SearchBuilder<BackupRecoveryProviderVO> backupProviderSearch;
public BackupRecoveryProviderDaoImpl() {
}
@PostConstruct
protected void init() {
backupProviderSearch = createSearchBuilder();
backupProviderSearch.and("zoneid", backupProviderSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
backupProviderSearch.and("provider", backupProviderSearch.entity().getProviderName(), SearchCriteria.Op.EQ);
backupProviderSearch.done();
}
@Override
public List<BackupRecoveryProviderVO> listByZone(long zoneId) {
SearchCriteria<BackupRecoveryProviderVO> sc = backupProviderSearch.create();
sc.setParameters("zoneid", zoneId);
return listBy(sc);
}
@Override
public List<BackupRecoveryProviderVO> listByZoneAndProvider(long zoneId, String provider) {
SearchCriteria<BackupRecoveryProviderVO> sc = backupProviderSearch.create();
sc.setParameters("zoneid", zoneId);
sc.setParameters("provider", provider);
return listBy(sc);
}
}

View File

@ -0,0 +1,125 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.impl;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.GenerationType;
import java.util.UUID;
@Entity
@Table(name = "backup_and_recovery_providers")
public class BackupRecoveryProviderVO implements InternalIdentity, Identity {
public BackupRecoveryProviderVO() {
this.uuid = UUID.randomUUID().toString();
}
public BackupRecoveryProviderVO(final long hostId, final String name, final long zoneId, final String url, final String provider) {
this();
this.name = name;
this.zoneId = zoneId;
this.hostId = hostId;
this.provider = provider;
this.url = url;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "uuid")
private String uuid;
@Column(name = "host_id")
private long hostId;
@Column(name = "name")
private String name;
@Column(name = "url", length = 2048)
private String url;
@Column(name = "zone_id")
private long zoneId;
@Column(name = "provider")
private String provider;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Override
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public long getHostId() {
return hostId;
}
public void setHostId(long hostId) {
this.hostId = hostId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public long getZoneId() {
return zoneId;
}
public void setZoneId(long zoneId) {
this.zoneId = zoneId;
}
public String getProviderName() {
return provider;
}
public void setProviderName(String provider) {
this.provider = provider;
}
}

View File

@ -0,0 +1,155 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.backuprecovery.resource;
import com.cloud.agent.IAgentControl;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.host.Host;
import com.cloud.resource.ServerResource;
import org.apache.cloudstack.framework.backuprecovery.agent.api.StartupBackupRecoveryProviderCommand;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import javax.naming.ConfigurationException;
import java.util.Map;
public class BackupRecoveryResource implements ServerResource {
private static final Logger s_logger = Logger.getLogger(BackupRecoveryResource.class);
private String name;
private String zoneId;
private String guid;
@Override
public boolean configure(String name, Map<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;
}
}

View File

@ -0,0 +1,21 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
name=backup-and-recovery
parent=backend

View File

@ -0,0 +1,37 @@
<!--
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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
>
<bean class="org.apache.cloudstack.spring.lifecycle.registry.RegistryLifecycle">
<property name="registry" ref="backupRecoveryRegistry" />
<property name="typeClass" value="org.apache.cloudstack.framework.backuprecovery.BackupRecoveryProvider" />
</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>

View File

@ -58,5 +58,6 @@
<module>security</module>
<module>agent-lb</module>
<module>direct-download</module>
<module>backup-and-recovery</module>
</modules>
</project>

View File

@ -0,0 +1,36 @@
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-backup-and-recovery-dummy</artifactId>
<name>Apache CloudStack Plugin - Backup and Recovery Dummy Plugin</name>
<parent>
<artifactId>cloudstack-plugins</artifactId>
<groupId>org.apache.cloudstack</groupId>
<version>4.12.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-backup-and-recovery</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,40 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.backuprecovery.element;
import org.apache.cloudstack.backuprecovery.resource.DummyBackupRecoveryResource;
import org.apache.cloudstack.framework.backuprecovery.element.BackupRecoveryElement;
import org.apache.cloudstack.framework.backuprecovery.helper.BackupRecoveryHelper;
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
import javax.naming.ConfigurationException;
import java.util.Map;
public class DummyBackupRecoveryElement extends BackupRecoveryElement {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
BackupRecoveryHelper.addProvider("Dummy", this);
return true;
}
@Override
public BackupRecoveryResource createNewResource() {
return new DummyBackupRecoveryResource();
}
}

View File

@ -0,0 +1,100 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.backuprecovery.resource;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyAnswer;
import org.apache.cloudstack.framework.backuprecovery.agent.api.AssignVMToBackupPolicyCommand;
import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyAnswer;
import org.apache.cloudstack.framework.backuprecovery.agent.api.CheckBackupPolicyCommand;
import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesAnswer;
import org.apache.cloudstack.framework.backuprecovery.agent.api.ListBackupPoliciesCommand;
import org.apache.cloudstack.framework.backuprecovery.agent.api.to.BackupPolicyTO;
import org.apache.cloudstack.framework.backuprecovery.resource.BackupRecoveryResource;
import org.apache.log4j.Logger;
import javax.naming.ConfigurationException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class DummyBackupRecoveryResource extends BackupRecoveryResource {
private static final Logger s_logger = Logger.getLogger(DummyBackupRecoveryResource.class);
private BackupPolicyTO policy1 = new BackupPolicyTO("aaaa-aaaa", "Policy A", "Gold policy");
private BackupPolicyTO policy2 = new BackupPolicyTO("bbbb-bbbb", "Policy B", "Silver policy");
private List<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";
}
}

View File

@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name=dummy-backup-recovery
parent=backup-and-recovery

View File

@ -0,0 +1,28 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
</beans>

View File

@ -110,6 +110,7 @@
<module>database/quota</module>
<module>integrations/cloudian</module>
<module>integrations/prometheus</module>
<module>backup-and-recovery/dummy</module>
</modules>
<dependencies>

View File

@ -190,7 +190,8 @@ known_categories = {
'CA': 'Certificate',
'listElastistorInterface': 'Misc',
'cloudian': 'Cloudian',
'Sioc' : 'Sioc'
'Sioc' : 'Sioc',
'BackupRecovery' : 'BackupRecovery'
}