|
1 |
| -package com.spectralogic.ds3client.integration.test.helpers; |
2 |
| - |
3 |
| -import com.spectralogic.ds3client.Ds3Client; |
4 |
| -import com.spectralogic.ds3client.commands.spectrads3.*; |
5 |
| -import com.spectralogic.ds3client.models.ChecksumType; |
6 |
| -import com.spectralogic.ds3client.models.PoolType; |
7 |
| - |
8 |
| -import java.io.IOException; |
9 |
| -import java.security.SignatureException; |
10 |
| -import java.util.UUID; |
11 |
| - |
12 |
| -import static com.spectralogic.ds3client.integration.test.helpers.ABMTestHelper.*; |
13 |
| - |
14 |
| -/** |
15 |
| - * This is a testing utility designed for creating a temporary data policy, storage domain, |
16 |
| - * and partition for use in the integration tests to avoid error if the BP does not currently |
17 |
| - * have a partition available for running the unit tests. |
18 |
| - */ |
19 |
| -public class TempStorageUtil { |
20 |
| - |
21 |
| - private static final String DATA_POLICY_NAME = "_dp"; |
22 |
| - private static final String STORAGE_DOMAIN_NAME = "_sd"; |
23 |
| - private static final String POOL_PARTITION_NAME = "_pp"; |
24 |
| - |
25 |
| - /** |
26 |
| - * Sets up a temporary data policy with a temporary storage domain and partition |
27 |
| - * for use in integration tests where the user may not currently have access to |
28 |
| - * a partition. |
29 |
| - * @param testSetName The unique name of tests being run under this domain to |
30 |
| - * prevent race conditions between test setup and teardown |
31 |
| - */ |
32 |
| - public static TempStorageIds setup( |
33 |
| - final String testSetName, |
34 |
| - final UUID dataPolicyId, |
35 |
| - final Ds3Client client) throws IOException, SignatureException { |
36 |
| - //Create storage domain |
37 |
| - final PutStorageDomainSpectraS3Response storageDomainResponse = createStorageDomain( |
38 |
| - testSetName + STORAGE_DOMAIN_NAME, |
39 |
| - client); |
40 |
| - |
41 |
| - //Create pool partition |
42 |
| - final PutPoolPartitionSpectraS3Response poolPartitionResponse = createPoolPartition( |
43 |
| - testSetName + POOL_PARTITION_NAME, |
44 |
| - PoolType.ONLINE, |
45 |
| - client); |
46 |
| - |
47 |
| - //Create storage domain member linking pool partition to storage domain |
48 |
| - final PutPoolStorageDomainMemberSpectraS3Response memberResponse = createPoolStorageDomainMember( |
49 |
| - storageDomainResponse.getStorageDomainResult().getId(), |
50 |
| - poolPartitionResponse.getPoolPartitionResult().getId(), |
51 |
| - client); |
52 |
| - final UUID storageDomainMemberId = memberResponse.getStorageDomainMemberResult().getId(); |
53 |
| - |
54 |
| - //create data persistence rule |
55 |
| - final PutDataPersistenceRuleSpectraS3Response dataPersistenceResponse = createDataPersistenceRule( |
56 |
| - dataPolicyId, |
57 |
| - storageDomainResponse.getStorageDomainResult().getId(), |
58 |
| - client); |
59 |
| - final UUID dataPersistenceRuleId = dataPersistenceResponse.getDataPersistenceRuleResult().getDataPolicyId(); |
60 |
| - |
61 |
| - return new TempStorageIds(storageDomainMemberId, dataPersistenceRuleId); |
62 |
| - } |
63 |
| - |
64 |
| - /** |
65 |
| - * Tears down the temporary test environment |
66 |
| - */ |
67 |
| - public static void teardown( |
68 |
| - final String testSetName, |
69 |
| - final TempStorageIds ids, |
70 |
| - final Ds3Client client) throws IOException, SignatureException { |
71 |
| - deleteDataPersistenceRule(ids.getDataPersistenceRuleId(), client); |
72 |
| - deleteDataPolicy(testSetName + DATA_POLICY_NAME, client); |
73 |
| - deleteStorageDomainMember(ids.getStorageDomainMemberId(), client); |
74 |
| - deleteStorageDomain(testSetName + STORAGE_DOMAIN_NAME, client); |
75 |
| - deletePoolPartition(testSetName + POOL_PARTITION_NAME, client); |
76 |
| - } |
77 |
| - |
78 |
| - /** |
79 |
| - * Creates a Data Policy with the specified checksum type and end-to-end crc requirement |
80 |
| - */ |
81 |
| - public static UUID setupDataPolicy( |
82 |
| - final String testSetName, |
83 |
| - final boolean withEndToEndCrcRequired, |
84 |
| - final ChecksumType.Type checksumType, |
85 |
| - final Ds3Client client) throws IOException, SignatureException { |
86 |
| - final PutDataPolicySpectraS3Response dataPolicyResponse = client.putDataPolicySpectraS3( |
87 |
| - new PutDataPolicySpectraS3Request(testSetName + DATA_POLICY_NAME) |
88 |
| - .withEndToEndCrcRequired(withEndToEndCrcRequired) |
89 |
| - .withChecksumType(checksumType)); |
90 |
| - return dataPolicyResponse.getDataPolicyResult().getId(); |
91 |
| - } |
92 |
| -} |
| 1 | +/* |
| 2 | + * ****************************************************************************** |
| 3 | + * Copyright 2014-2015 Spectra Logic Corporation. All Rights Reserved. |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use |
| 5 | + * this file except in compliance with the License. A copy of the License is located at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * or in the "license" file accompanying this file. |
| 10 | + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 11 | + * CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 12 | + * specific language governing permissions and limitations under the License. |
| 13 | + * **************************************************************************** |
| 14 | + */ |
| 15 | + |
| 16 | +package com.spectralogic.ds3client.integration.test.helpers; |
| 17 | + |
| 18 | +import com.spectralogic.ds3client.Ds3Client; |
| 19 | +import com.spectralogic.ds3client.commands.spectrads3.*; |
| 20 | +import com.spectralogic.ds3client.models.ChecksumType; |
| 21 | +import com.spectralogic.ds3client.models.PoolType; |
| 22 | + |
| 23 | +import java.io.IOException; |
| 24 | +import java.security.SignatureException; |
| 25 | +import java.util.UUID; |
| 26 | + |
| 27 | +import static com.spectralogic.ds3client.integration.test.helpers.ABMTestHelper.*; |
| 28 | + |
| 29 | +/** |
| 30 | + * This is a testing utility designed for creating a temporary data policy, storage domain, |
| 31 | + * and partition for use in the integration tests to avoid error if the BP does not currently |
| 32 | + * have a partition available for running the unit tests. |
| 33 | + */ |
| 34 | +public class TempStorageUtil { |
| 35 | + |
| 36 | + private static final String DATA_POLICY_NAME = "_dp"; |
| 37 | + private static final String STORAGE_DOMAIN_NAME = "_sd"; |
| 38 | + private static final String POOL_PARTITION_NAME = "_pp"; |
| 39 | + |
| 40 | + /** |
| 41 | + * Sets up a temporary data policy with a temporary storage domain and partition |
| 42 | + * for use in integration tests where the user may not currently have access to |
| 43 | + * a partition. |
| 44 | + * @param testSetName The unique name of tests being run under this domain to |
| 45 | + * prevent race conditions between test setup and teardown |
| 46 | + */ |
| 47 | + public static TempStorageIds setup( |
| 48 | + final String testSetName, |
| 49 | + final UUID dataPolicyId, |
| 50 | + final Ds3Client client) throws IOException, SignatureException { |
| 51 | + //Create storage domain |
| 52 | + final PutStorageDomainSpectraS3Response storageDomainResponse = createStorageDomain( |
| 53 | + testSetName + STORAGE_DOMAIN_NAME, |
| 54 | + client); |
| 55 | + |
| 56 | + //Create pool partition |
| 57 | + final PutPoolPartitionSpectraS3Response poolPartitionResponse = createPoolPartition( |
| 58 | + testSetName + POOL_PARTITION_NAME, |
| 59 | + PoolType.ONLINE, |
| 60 | + client); |
| 61 | + |
| 62 | + //Create storage domain member linking pool partition to storage domain |
| 63 | + final PutPoolStorageDomainMemberSpectraS3Response memberResponse = createPoolStorageDomainMember( |
| 64 | + storageDomainResponse.getStorageDomainResult().getId(), |
| 65 | + poolPartitionResponse.getPoolPartitionResult().getId(), |
| 66 | + client); |
| 67 | + final UUID storageDomainMemberId = memberResponse.getStorageDomainMemberResult().getId(); |
| 68 | + |
| 69 | + //create data persistence rule |
| 70 | + final PutDataPersistenceRuleSpectraS3Response dataPersistenceResponse = createDataPersistenceRule( |
| 71 | + dataPolicyId, |
| 72 | + storageDomainResponse.getStorageDomainResult().getId(), |
| 73 | + client); |
| 74 | + final UUID dataPersistenceRuleId = dataPersistenceResponse.getDataPersistenceRuleResult().getDataPolicyId(); |
| 75 | + |
| 76 | + return new TempStorageIds(storageDomainMemberId, dataPersistenceRuleId); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Tears down the temporary test environment |
| 81 | + */ |
| 82 | + public static void teardown( |
| 83 | + final String testSetName, |
| 84 | + final TempStorageIds ids, |
| 85 | + final Ds3Client client) throws IOException, SignatureException { |
| 86 | + deleteDataPersistenceRule(ids.getDataPersistenceRuleId(), client); |
| 87 | + deleteDataPolicy(testSetName + DATA_POLICY_NAME, client); |
| 88 | + deleteStorageDomainMember(ids.getStorageDomainMemberId(), client); |
| 89 | + deleteStorageDomain(testSetName + STORAGE_DOMAIN_NAME, client); |
| 90 | + deletePoolPartition(testSetName + POOL_PARTITION_NAME, client); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Creates a Data Policy with the specified checksum type and end-to-end crc requirement |
| 95 | + */ |
| 96 | + public static UUID setupDataPolicy( |
| 97 | + final String testSetName, |
| 98 | + final boolean withEndToEndCrcRequired, |
| 99 | + final ChecksumType.Type checksumType, |
| 100 | + final Ds3Client client) throws IOException, SignatureException { |
| 101 | + final PutDataPolicySpectraS3Response dataPolicyResponse = client.putDataPolicySpectraS3( |
| 102 | + new PutDataPolicySpectraS3Request(testSetName + DATA_POLICY_NAME) |
| 103 | + .withEndToEndCrcRequired(withEndToEndCrcRequired) |
| 104 | + .withChecksumType(checksumType).withAlwaysForcePutJobCreation(true)); |
| 105 | + client.modifyUserSpectraS3(new ModifyUserSpectraS3Request("spectra") |
| 106 | + .withDefaultDataPolicyId(dataPolicyResponse.getDataPolicyResult().getId())); |
| 107 | + return dataPolicyResponse.getDataPolicyResult().getId(); |
| 108 | + } |
| 109 | +} |
0 commit comments