Skip to content

Commit 5874150

Browse files
Merge branch 'master' into hide_ip_address_usages
2 parents 6464737 + 86fcb14 commit 5874150

File tree

272 files changed

+6049
-16520
lines changed

Some content is hidden

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

272 files changed

+6049
-16520
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import com.cloud.server.ResourceTag;
7171
import com.cloud.storage.GuestOS;
7272
import com.cloud.storage.GuestOSHypervisor;
73+
import com.cloud.storage.ImageStore;
7374
import com.cloud.storage.Snapshot;
7475
import com.cloud.storage.StoragePool;
7576
import com.cloud.storage.Volume;
@@ -239,6 +240,7 @@ public class EventTypes {
239240
public static final String EVENT_TEMPLATE_EXTRACT = "TEMPLATE.EXTRACT";
240241
public static final String EVENT_TEMPLATE_UPLOAD = "TEMPLATE.UPLOAD";
241242
public static final String EVENT_TEMPLATE_CLEANUP = "TEMPLATE.CLEANUP";
243+
public static final String EVENT_FILE_MIGRATE = "FILE.MIGRATE";
242244

243245
// Volume Events
244246
public static final String EVENT_VOLUME_CREATE = "VOLUME.CREATE";
@@ -329,6 +331,8 @@ public class EventTypes {
329331
public static final String EVENT_STORAGE_IP_RANGE_DELETE = "STORAGE.IP.RANGE.DELETE";
330332
public static final String EVENT_STORAGE_IP_RANGE_UPDATE = "STORAGE.IP.RANGE.UPDATE";
331333

334+
public static final String EVENT_IMAGE_STORE_DATA_MIGRATE = "IMAGE.STORE.MIGRATE.DATA";
335+
332336
// Configuration Table
333337
public static final String EVENT_CONFIGURATION_VALUE_EDIT = "CONFIGURATION.VALUE.EDIT";
334338

@@ -1021,6 +1025,8 @@ public class EventTypes {
10211025
entityEventDetails.put(EVENT_POD_ROLLING_MAINTENANCE, PodResponse.class);
10221026
entityEventDetails.put(EVENT_CLUSTER_ROLLING_MAINTENANCE, ClusterResponse.class);
10231027
entityEventDetails.put(EVENT_HOST_ROLLING_MAINTENANCE, HostResponse.class);
1028+
1029+
entityEventDetails.put(EVENT_IMAGE_STORE_DATA_MIGRATE, ImageStore.class);
10241030
}
10251031

10261032
public static String getEntityForEvent(String eventName) {

api/src/main/java/com/cloud/network/Networks.java

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.net.URISyntaxException;
2121

2222
import com.cloud.utils.exception.CloudRuntimeException;
23+
import org.apache.commons.lang3.StringUtils;
2324

2425
/**
2526
* Network includes all of the enums used within networking.
@@ -253,20 +254,42 @@ public static URI fromString(String candidate) {
253254
Long.parseLong(candidate);
254255
return Vlan.toUri(candidate);
255256
} catch (NumberFormatException nfe) {
256-
if (com.cloud.dc.Vlan.UNTAGGED.equalsIgnoreCase(candidate)) {
257-
return Native.toUri(candidate);
258-
}
259-
try {
260-
URI uri = new URI(candidate);
261-
BroadcastDomainType tiep = getSchemeValue(uri);
262-
if (tiep.scheme != null && tiep.scheme.equals(uri.getScheme())) {
263-
return uri;
264-
} else {
265-
throw new CloudRuntimeException("string '" + candidate + "' has an unknown BroadcastDomainType.");
266-
}
267-
} catch (URISyntaxException e) {
268-
throw new CloudRuntimeException("string is not a broadcast URI: " + candidate);
257+
return getVlanUriWhenNumberFormatException(candidate);
258+
}
259+
}
260+
261+
/**
262+
* This method is called in case of NumberFormatException is thrown when parsing the String into long
263+
*/
264+
private static URI getVlanUriWhenNumberFormatException(String candidate) {
265+
if(StringUtils.isBlank(candidate)) {
266+
throw new CloudRuntimeException("Expected VLAN or VXLAN but got a null isolation method");
267+
}
268+
if (com.cloud.dc.Vlan.UNTAGGED.equalsIgnoreCase(candidate)) {
269+
return Native.toUri(candidate);
270+
}
271+
try {
272+
URI uri = new URI(candidate);
273+
BroadcastDomainType tiep = getSchemeValue(uri);
274+
if (tiep.scheme != null && tiep.scheme.equals(uri.getScheme())) {
275+
return uri;
276+
} else {
277+
throw new CloudRuntimeException("string '" + candidate + "' has an unknown BroadcastDomainType.");
269278
}
279+
} catch (URISyntaxException e) {
280+
throw new CloudRuntimeException("string is not a broadcast URI: " + candidate);
281+
}
282+
}
283+
284+
/**
285+
* Encodes a string into a BroadcastUri, according to the given BroadcastDomainType
286+
*/
287+
public static URI encodeStringIntoBroadcastUri(String candidate, BroadcastDomainType isolationMethod) {
288+
try{
289+
Long.parseLong(candidate);
290+
return isolationMethod.toUri(candidate);
291+
} catch (NumberFormatException nfe) {
292+
return getVlanUriWhenNumberFormatException(candidate);
270293
}
271294
}
272295
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,6 @@ public interface StorageService {
102102
*/
103103
ImageStore migrateToObjectStore(String name, String url, String providerName, Map<String, String> details) throws DiscoveryException;
104104

105+
ImageStore updateImageStoreStatus(Long id, Boolean readonly);
106+
105107
}

api/src/main/java/com/cloud/storage/Volume.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public String getDescription() {
8484
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Resizing, Event.OperationFailed, Ready, null));
8585
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Allocated, Event.UploadRequested, UploadOp, null));
8686
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Uploaded, Event.CopyRequested, Copying, null));
87+
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Ready, Event.OperationSucceeded, Ready, null));
88+
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Ready, Event.OperationFailed, Ready, null));
8789
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Copying, Event.OperationSucceeded, Ready, Arrays.asList(new StateMachine2.Transition.Impact[]{StateMachine2.Transition.Impact.USAGE})));
8890
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Copying, Event.OperationFailed, Uploaded, null));
8991
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(UploadOp, Event.DestroyRequested, Destroy, null));

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public class ApiConstants {
114114
public static final String DISK_IO_WRITE = "diskiowrite";
115115
public static final String DISK_IO_PSTOTAL = "diskiopstotal";
116116
public static final String DISK_SIZE = "disksize";
117+
public static final String DOWNLOAD_DETAILS = "downloaddetails";
117118
public static final String UTILIZATION = "utilization";
118119
public static final String DRIVER = "driver";
119120
public static final String ROOT_DISK_SIZE = "rootdisksize";
@@ -235,6 +236,7 @@ public class ApiConstants {
235236
public static final String MAX_MEMORY = "maxmemory";
236237
public static final String MIN_CPU_NUMBER = "mincpunumber";
237238
public static final String MIN_MEMORY = "minmemory";
239+
public static final String MIGRATION_TYPE = "migrationtype";
238240
public static final String MEMORY = "memory";
239241
public static final String MODE = "mode";
240242
public static final String KEEPALIVE_ENABLED = "keepaliveenabled";
@@ -355,6 +357,7 @@ public class ApiConstants {
355357
public static final String TARGET_IQN = "targetiqn";
356358
public static final String TEMPLATE_FILTER = "templatefilter";
357359
public static final String TEMPLATE_ID = "templateid";
360+
public static final String TEMPLATE_IDS = "templateids";
358361
public static final String TEMPLATE_NAME = "templatename";
359362
public static final String ISO_ID = "isoid";
360363
public static final String TIMEOUT = "timeout";
@@ -719,6 +722,7 @@ public class ApiConstants {
719722
public static final String AFFINITY_GROUP_ID = "affinitygroupid";
720723
public static final String DEPLOYMENT_PLANNER = "deploymentplanner";
721724
public static final String ACL_ID = "aclid";
725+
public static final String ACL_NAME = "aclname";
722726
public static final String NUMBER = "number";
723727
public static final String IS_DYNAMICALLY_SCALABLE = "isdynamicallyscalable";
724728
public static final String ROUTING = "isrouting";
@@ -788,6 +792,8 @@ public class ApiConstants {
788792
public static final String EXITCODE = "exitcode";
789793
public static final String TARGET_ID = "targetid";
790794
public static final String FILES = "files";
795+
public static final String SRC_POOL = "srcpool";
796+
public static final String DEST_POOLS = "destpools";
791797
public static final String VOLUME_IDS = "volumeids";
792798

793799
public static final String ROUTER_ID = "routerid";

api/src/main/java/org/apache/cloudstack/api/BaseCmd.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerService;
4141
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
4242
import org.apache.cloudstack.query.QueryService;
43+
import org.apache.cloudstack.storage.ImageStoreService;
4344
import org.apache.cloudstack.usage.UsageService;
4445
import org.apache.log4j.Logger;
4546

@@ -131,6 +132,8 @@ public static enum CommandType {
131132
@Inject
132133
public TemplateApiService _templateService;
133134
@Inject
135+
public ImageStoreService _imageStoreService;
136+
@Inject
134137
public SecurityGroupService _securityGroupService;
135138
@Inject
136139
public SnapshotApiService _snapshotService;

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.storage;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiConstants;
2321
import org.apache.cloudstack.api.BaseListCmd;
2422
import org.apache.cloudstack.api.Parameter;
2523
import org.apache.cloudstack.api.response.ImageStoreResponse;
2624
import org.apache.cloudstack.api.response.ListResponse;
2725
import org.apache.cloudstack.api.response.ZoneResponse;
26+
import org.apache.log4j.Logger;
2827

2928
@APICommand(name = "listImageStores", description = "Lists image stores.", responseObject = ImageStoreResponse.class, since = "4.2.0",
3029
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -52,6 +51,9 @@ public class ListImageStoresCmd extends BaseListCmd {
5251
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ImageStoreResponse.class, description = "the ID of the storage pool")
5352
private Long id;
5453

54+
@Parameter(name = ApiConstants.READ_ONLY, type = CommandType.BOOLEAN, entityType = ImageStoreResponse.class, description = "read-only status of the image store", since = "4.15.0")
55+
private Boolean readonly;
56+
5557
/////////////////////////////////////////////////////
5658
/////////////////// Accessors ///////////////////////
5759
/////////////////////////////////////////////////////
@@ -80,6 +82,10 @@ public void setProvider(String provider) {
8082
this.provider = provider;
8183
}
8284

85+
public Boolean getReadonly() {
86+
return readonly;
87+
}
88+
8389
/////////////////////////////////////////////////////
8490
/////////////// API Implementation///////////////////
8591
/////////////////////////////////////////////////////
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
18+
package org.apache.cloudstack.api.command.admin.storage;
19+
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.acl.RoleType;
23+
import org.apache.cloudstack.api.APICommand;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.BaseAsyncCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.response.ImageStoreResponse;
28+
import org.apache.cloudstack.api.response.MigrationResponse;
29+
import org.apache.cloudstack.context.CallContext;
30+
import org.apache.log4j.Logger;
31+
32+
import com.cloud.event.EventTypes;
33+
34+
@APICommand(name = MigrateSecondaryStorageDataCmd.APINAME,
35+
description = "migrates data objects from one secondary storage to destination image store(s)",
36+
responseObject = MigrationResponse.class,
37+
requestHasSensitiveInfo = false,
38+
responseHasSensitiveInfo = false,
39+
since = "4.15.0",
40+
authorized = {RoleType.Admin})
41+
public class MigrateSecondaryStorageDataCmd extends BaseAsyncCmd {
42+
43+
public static final Logger LOGGER = Logger.getLogger(MigrateSecondaryStorageDataCmd.class.getName());
44+
45+
public static final String APINAME = "migrateSecondaryStorageData";
46+
47+
/////////////////////////////////////////////////////
48+
//////////////// API parameters /////////////////////
49+
/////////////////////////////////////////////////////
50+
51+
@Parameter(name = ApiConstants.SRC_POOL,
52+
type = CommandType.UUID,
53+
entityType = ImageStoreResponse.class,
54+
description = "id of the image store from where the data is to be migrated",
55+
required = true)
56+
private Long id;
57+
58+
@Parameter(name = ApiConstants.DEST_POOLS,
59+
type = CommandType.LIST,
60+
collectionType = CommandType.UUID,
61+
entityType = ImageStoreResponse.class,
62+
description = "id(s) of the destination secondary storage pool(s) to which the templates are to be migrated",
63+
required = true)
64+
private List<Long> migrateTo;
65+
66+
@Parameter(name = ApiConstants.MIGRATION_TYPE,
67+
type = CommandType.STRING,
68+
description = "Balance: if you want data to be distributed evenly among the destination stores, " +
69+
"Complete: If you want to migrate the entire data from source image store to the destination store(s). Default: Complete")
70+
private String migrationType;
71+
72+
/////////////////////////////////////////////////////
73+
/////////////////// Accessors ///////////////////////
74+
/////////////////////////////////////////////////////
75+
76+
public Long getId() {
77+
return id;
78+
}
79+
80+
public List<Long> getMigrateTo() {
81+
return migrateTo;
82+
}
83+
84+
public String getMigrationType() {
85+
return migrationType;
86+
}
87+
88+
@Override
89+
public String getEventType() {
90+
return EventTypes.EVENT_IMAGE_STORE_DATA_MIGRATE;
91+
}
92+
93+
@Override
94+
public String getEventDescription() {
95+
return "Attempting to migrate files/data objects ";
96+
}
97+
98+
@Override
99+
public void execute() {
100+
MigrationResponse response = _imageStoreService.migrateData(this);
101+
response.setObjectName("imagestore");
102+
this.setResponseObject(response);
103+
CallContext.current().setEventDetails(response.getMessage());
104+
}
105+
106+
@Override
107+
public String getCommandName() {
108+
return APINAME.toLowerCase() + BaseAsyncCmd.RESPONSE_SUFFIX;
109+
}
110+
111+
@Override
112+
public long getEntityOwnerId() {
113+
return CallContext.current().getCallingAccountId();
114+
}
115+
}

0 commit comments

Comments
 (0)