Skip to content

Commit 6be228a

Browse files
committed
CLOUDSTACK-4024:Provide a way to upgrade from existing NFS secondary
storage to S3.
1 parent 271a7df commit 6be228a

47 files changed

Lines changed: 1238 additions & 448 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/event/EventTypes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ public class EventTypes {
449449

450450
public static final String EVENT_UCS_ASSOCIATED_PROFILE = "UCS.ASSOCIATEPROFILE";
451451

452+
// Object store migration
453+
public static final String EVENT_MIGRATE_PREPARE_SECONDARY_STORAGE = "MIGRATE.PREPARE.SS";
454+
452455
static {
453456

454457
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking

api/src/com/cloud/storage/StorageService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
2323
import org.apache.cloudstack.api.command.admin.storage.CreateSecondaryStagingStoreCmd;
2424
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
25-
import org.apache.cloudstack.api.command.admin.storage.DeleteSecondaryStagingStoreCmd;
2625
import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
2726
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
27+
import org.apache.cloudstack.api.command.admin.storage.DeleteSecondaryStagingStoreCmd;
2828
import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
2929

3030
import com.cloud.exception.DiscoveryException;
@@ -97,4 +97,18 @@ public StoragePool cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMainte
9797

9898
ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
9999

100+
/**
101+
* Prepare NFS secondary storage for object store migration
102+
*
103+
* @param cmd
104+
* - the command specifying secondaryStorageId
105+
* @return the storage pool
106+
* @throws ResourceUnavailableException
107+
* TODO
108+
* @throws InsufficientCapacityException
109+
* TODO
110+
*/
111+
public ImageStore prepareSecondaryStorageForObjectStoreMigration(Long storeId) throws ResourceUnavailableException,
112+
InsufficientCapacityException;
113+
100114
}

api/src/org/apache/cloudstack/api/ApiCommandJobType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public enum ApiCommandJobType {
2828
SystemVm,
2929
Host,
3030
StoragePool,
31+
ImageStore,
3132
IpAddress,
3233
PortableIpAddress,
3334
SecurityGroup,
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.admin.storage;
18+
19+
import org.apache.log4j.Logger;
20+
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiCommandJobType;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseAsyncCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.ImageStoreResponse;
29+
import org.apache.cloudstack.context.CallContext;
30+
31+
import com.cloud.event.EventTypes;
32+
import com.cloud.exception.InsufficientCapacityException;
33+
import com.cloud.exception.ResourceUnavailableException;
34+
import com.cloud.storage.ImageStore;
35+
import com.cloud.user.Account;
36+
37+
@APICommand(name = "prepareSecondaryStorageForMigration", description = "Prepare a NFS secondary storage to migrate to use object store like S3", responseObject = ImageStoreResponse.class)
38+
public class PrepareSecondaryStorageForMigrationCmd extends BaseAsyncCmd {
39+
public static final Logger s_logger = Logger.getLogger(PrepareSecondaryStorageForMigrationCmd.class.getName());
40+
private static final String s_name = "preparesecondarystorageformigrationresponse";
41+
42+
/////////////////////////////////////////////////////
43+
//////////////// API parameters /////////////////////
44+
/////////////////////////////////////////////////////
45+
46+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ImageStoreResponse.class,
47+
required = true, description = "Secondary image store ID")
48+
private Long id;
49+
50+
/////////////////////////////////////////////////////
51+
/////////////////// Accessors ///////////////////////
52+
/////////////////////////////////////////////////////
53+
54+
public Long getId() {
55+
return id;
56+
}
57+
58+
/////////////////////////////////////////////////////
59+
/////////////// API Implementation///////////////////
60+
/////////////////////////////////////////////////////
61+
62+
@Override
63+
public String getCommandName() {
64+
return s_name;
65+
}
66+
67+
@Override
68+
public ApiCommandJobType getInstanceType() {
69+
return ApiCommandJobType.ImageStore;
70+
}
71+
72+
@Override
73+
public Long getInstanceId() {
74+
return getId();
75+
}
76+
77+
@Override
78+
public long getEntityOwnerId() {
79+
Account account = CallContext.current().getCallingAccount();
80+
if (account != null) {
81+
return account.getId();
82+
}
83+
84+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
85+
}
86+
87+
@Override
88+
public String getEventType() {
89+
return EventTypes.EVENT_MIGRATE_PREPARE_SECONDARY_STORAGE;
90+
}
91+
92+
@Override
93+
public String getEventDescription() {
94+
return "preparing secondary storage: " + getId() + " for object store migration";
95+
}
96+
97+
@Override
98+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException{
99+
ImageStore result = _storageService.prepareSecondaryStorageForObjectStoreMigration(getId());
100+
if (result != null){
101+
ImageStoreResponse response = _responseGenerator.createImageStoreResponse(result);
102+
response.setResponseName(getCommandName());
103+
response.setResponseName("secondarystorage");
104+
setResponseObject(response);
105+
} else {
106+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to prepare secondary storage for object store migration");
107+
}
108+
}
109+
}

client/tomcatconf/commands.properties.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ deleteImageStore=1
256256
createSecondaryStagingStore=1
257257
listSecondaryStagingStores=1
258258
deleteSecondaryStagingStore=1
259+
prepareSecondaryStorageForMigration=1
259260

260261
#### host commands
261262
addHost=3

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreLifeCycle.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ public interface DataStoreLifeCycle {
3737
boolean cancelMaintain(DataStore store);
3838

3939
boolean deleteDataStore(DataStore store);
40+
41+
boolean migrateToObjectStore(DataStore store);
4042
}

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.cloudstack.engine.subsystem.api.storage;
2020

2121
import java.util.List;
22+
2223
import com.cloud.storage.DataStoreRole;
2324

2425
public interface DataStoreManager {
@@ -37,4 +38,6 @@ public interface DataStoreManager {
3738
DataStore getImageCacheStore(long zoneId);
3839

3940
List<DataStore> listImageStores();
41+
42+
List<DataStore> listImageCacheStores();
4043
}

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.cloudstack.engine.subsystem.api.storage;
2020

21+
import java.util.List;
22+
2123
import com.cloud.storage.DataStoreRole;
2224

2325
public interface SnapshotDataFactory {
@@ -26,4 +28,6 @@ public interface SnapshotDataFactory {
2628
SnapshotInfo getSnapshot(DataObject obj, DataStore store);
2729

2830
SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role);
31+
32+
List<SnapshotInfo> listSnapshotOnCache(long snapshotId);
2933
}

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateDataFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.cloudstack.engine.subsystem.api.storage;
2020

21+
import java.util.List;
22+
2123
import com.cloud.storage.DataStoreRole;
2224

2325
public interface TemplateDataFactory {
@@ -28,4 +30,8 @@ public interface TemplateDataFactory {
2830
TemplateInfo getTemplate(long templateId, DataStoreRole storeRole);
2931

3032
TemplateInfo getTemplate(long templateId, DataStoreRole storeRole, Long zoneId);
33+
34+
TemplateInfo getReadyTemplateOnCache(long templateId);
35+
36+
List<TemplateInfo> listTemplateOnCache(long templateId);
3137
}

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public TemplateApiResult(TemplateInfo template) {
3636
}
3737

3838
public TemplateInfo getTemplate() {
39-
return this.template;
39+
return template;
4040
}
4141
}
4242

@@ -54,6 +54,8 @@ AsyncCallFuture<TemplateApiResult> createTemplateFromVolumeAsync(VolumeInfo volu
5454

5555
AsyncCallFuture<TemplateApiResult> prepareTemplateOnPrimary(TemplateInfo srcTemplate, StoragePool pool);
5656

57+
void syncTemplateToRegionStore(long templateId, DataStore store);
58+
5759
void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId);
5860

5961
void handleTemplateSync(DataStore store);
@@ -62,5 +64,7 @@ AsyncCallFuture<TemplateApiResult> createTemplateFromVolumeAsync(VolumeInfo volu
6264

6365
void addSystemVMTemplatesToSecondary(DataStore store);
6466

67+
void associateTemplateToZone(long templateId, Long zoneId);
68+
6569
void associateCrosszoneTemplatesToZone(long dcId);
6670
}

0 commit comments

Comments
 (0)