Skip to content

Commit d700e2d

Browse files
Merge branch '4.20' into 4.22
2 parents a8f1e4a + 26b5765 commit d700e2d

File tree

55 files changed

+1471
-947
lines changed

Some content is hidden

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

55 files changed

+1471
-947
lines changed

api/src/main/java/org/apache/cloudstack/alert/AlertService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ private AlertType(short type, String name, boolean isDefault) {
7171
public static final AlertType ALERT_TYPE_HA_ACTION = new AlertType((short)30, "ALERT.HA.ACTION", true);
7272
public static final AlertType ALERT_TYPE_CA_CERT = new AlertType((short)31, "ALERT.CA.CERT", true);
7373
public static final AlertType ALERT_TYPE_VM_SNAPSHOT = new AlertType((short)32, "ALERT.VM.SNAPSHOT", true);
74-
public static final AlertType ALERT_TYPE_VR_PUBLIC_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PUBLIC.IFACE.MTU", true);
75-
public static final AlertType ALERT_TYPE_VR_PRIVATE_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PRIVATE.IFACE.MTU", true);
74+
public static final AlertType ALERT_TYPE_VR_PUBLIC_IFACE_MTU = new AlertType((short)33, "ALERT.VR.PUBLIC.IFACE.MTU", true);
75+
public static final AlertType ALERT_TYPE_VR_PRIVATE_IFACE_MTU = new AlertType((short)34, "ALERT.VR.PRIVATE.IFACE.MTU", true);
7676
public static final AlertType ALERT_TYPE_EXTENSION_PATH_NOT_READY = new AlertType((short)33, "ALERT.TYPE.EXTENSION.PATH.NOT.READY", true);
7777
public static final AlertType ALERT_TYPE_BACKUP_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_BACKUP_STORAGE, "ALERT.STORAGE.BACKUP", true);
7878
public static final AlertType ALERT_TYPE_OBJECT_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_OBJECT_STORAGE, "ALERT.STORAGE.OBJECT", true);

api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
import com.cloud.exception.DiscoveryException;
3030
import com.cloud.storage.ImageStore;
3131
import com.cloud.user.Account;
32+
import org.apache.commons.collections.MapUtils;
33+
34+
import java.util.Collection;
35+
import java.util.HashMap;
36+
import java.util.Map;
3237

3338
@APICommand(name = "addSecondaryStorage", description = "Adds secondary storage.", responseObject = ImageStoreResponse.class,
3439
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -44,6 +49,9 @@ public class AddSecondaryStorageCmd extends BaseCmd {
4449
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "The Zone ID for the secondary storage")
4550
protected Long zoneId;
4651

52+
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "Details in key/value pairs using format details[i].keyname=keyvalue. Example: details[0].copytemplatesfromothersecondarystorages=true")
53+
protected Map details;
54+
4755
/////////////////////////////////////////////////////
4856
/////////////////// Accessors ///////////////////////
4957
/////////////////////////////////////////////////////
@@ -56,6 +64,20 @@ public Long getZoneId() {
5664
return zoneId;
5765
}
5866

67+
public Map<String, String> getDetails() {
68+
Map<String, String> detailsMap = new HashMap<>();
69+
if (MapUtils.isNotEmpty(details)) {
70+
Collection<?> props = details.values();
71+
for (Object prop : props) {
72+
HashMap<String, String> detail = (HashMap<String, String>) prop;
73+
for (Map.Entry<String, String> entry: detail.entrySet()) {
74+
detailsMap.put(entry.getKey(),entry.getValue());
75+
}
76+
}
77+
}
78+
return detailsMap;
79+
}
80+
5981
/////////////////////////////////////////////////////
6082
/////////////// API Implementation///////////////////
6183
/////////////////////////////////////////////////////
@@ -68,7 +90,7 @@ public long getEntityOwnerId() {
6890
@Override
6991
public void execute(){
7092
try{
71-
ImageStore result = _storageService.discoverImageStore(null, getUrl(), "NFS", getZoneId(), null);
93+
ImageStore result = _storageService.discoverImageStore(null, getUrl(), "NFS", getZoneId(), getDetails());
7294
ImageStoreResponse storeResponse = null;
7395
if (result != null ) {
7496
storeResponse = _responseGenerator.createImageStoreResponse(result);

api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ public void execute() {
271271
}
272272

273273
public Snapshot.LocationType getLocationType() {
274-
275-
if (Snapshot.LocationType.values() == null || Snapshot.LocationType.values().length == 0 || locationType == null) {
274+
if (locationType == null) {
276275
return null;
277276
}
278277

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/StorageOrchestrationService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import org.apache.cloudstack.api.response.MigrationResponse;
2424
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
25-
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
2625
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult;
2726
import org.apache.cloudstack.storage.ImageStoreService.MigrationPolicy;
2827

@@ -31,5 +30,5 @@ public interface StorageOrchestrationService {
3130

3231
MigrationResponse migrateResources(Long srcImgStoreId, Long destImgStoreId, List<Long> templateIdList, List<Long> snapshotIdList);
3332

34-
Future<TemplateApiResult> orchestrateTemplateCopyToImageStore(TemplateInfo source, DataStore destStore);
33+
Future<TemplateApiResult> orchestrateTemplateCopyFromSecondaryStores(long templateId, DataStore destStore);
3534
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,6 @@ public TemplateInfo getTemplate() {
8080
List<DatadiskTO> getTemplateDatadisksOnImageStore(TemplateInfo templateInfo, String configurationId);
8181

8282
AsyncCallFuture<TemplateApiResult> copyTemplateToImageStore(DataObject source, DataStore destStore);
83-
}
83+
84+
void handleTemplateCopyFromSecondaryStores(long templateId, DataStore destStore);
85+
}

engine/components-api/src/main/java/com/cloud/alert/AlertManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ public interface AlertManager extends Manager, AlertService {
5454
void recalculateCapacity();
5555

5656
void sendAlert(AlertType alertType, long dataCenterId, Long podId, String subject, String body);
57-
5857
}

engine/components-api/src/main/java/com/cloud/resource/ResourceManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public interface ResourceManager extends ResourceService, Configurable {
5757

5858
ConfigKey<Boolean> KvmSshToAgentEnabled = new ConfigKey<>("Advanced", Boolean.class,
5959
"kvm.ssh.to.agent","true",
60-
"Number of retries when preparing a host into Maintenance Mode is faulty before failing",
61-
false);
60+
"True if the management server will restart the agent service via SSH into the KVM hosts after or during maintenance operations",
61+
true);
6262

6363
ConfigKey<String> HOST_MAINTENANCE_LOCAL_STRATEGY = new ConfigKey<>(String.class,
6464
"host.maintenance.local.storage.strategy", "Advanced","Error",

engine/components-api/src/main/java/com/cloud/storage/StorageManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ public interface StorageManager extends StorageService {
228228
ConfigKey.Scope.Global,
229229
null);
230230

231-
ConfigKey<Boolean> COPY_PUBLIC_TEMPLATES_FROM_OTHER_STORAGES = new ConfigKey<>(Boolean.class, "copy.public.templates.from.other.storages",
232-
"Storage", "true", "Allow SSVMs to try copying public templates from one secondary storage to another instead of downloading them from the source.",
231+
ConfigKey<Boolean> COPY_TEMPLATES_FROM_OTHER_SECONDARY_STORAGES = new ConfigKey<>(Boolean.class, "copy.templates.from.other.secondary.storages",
232+
"Storage", "true", "When enabled, this feature allows templates to be copied from existing Secondary Storage servers (within the same zone or across zones) " +
233+
"while adding a new Secondary Storage. If the copy operation fails, the system falls back to downloading the template from the source URL.",
233234
true, ConfigKey.Scope.Zone, null);
234235

235236
/**

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/StorageOrchestrator.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
import javax.inject.Inject;
3737
import javax.naming.ConfigurationException;
3838

39+
import com.cloud.dc.dao.DataCenterDao;
40+
import com.cloud.storage.dao.VMTemplateDao;
41+
import com.cloud.template.TemplateManager;
3942
import org.apache.cloudstack.api.response.MigrationResponse;
4043
import org.apache.cloudstack.engine.orchestration.service.StorageOrchestrationService;
4144
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
@@ -45,6 +48,7 @@
4548
import org.apache.cloudstack.engine.subsystem.api.storage.SecondaryStorageService.DataObjectResult;
4649
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
4750
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
51+
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
4852
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
4953
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
5054
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult;
@@ -103,6 +107,15 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra
103107
VolumeDataStoreDao volumeDataStoreDao;
104108
@Inject
105109
DataMigrationUtility migrationHelper;
110+
@Inject
111+
TemplateManager templateManager;
112+
@Inject
113+
VMTemplateDao templateDao;
114+
@Inject
115+
TemplateDataFactory templateDataFactory;
116+
@Inject
117+
DataCenterDao dcDao;
118+
106119

107120
ConfigKey<Double> ImageStoreImbalanceThreshold = new ConfigKey<>("Advanced", Double.class,
108121
"image.store.imbalance.threshold",
@@ -304,8 +317,9 @@ public MigrationResponse migrateResources(Long srcImgStoreId, Long destImgStoreI
304317
}
305318

306319
@Override
307-
public Future<TemplateApiResult> orchestrateTemplateCopyToImageStore(TemplateInfo source, DataStore destStore) {
308-
return submit(destStore.getScope().getScopeId(), new CopyTemplateTask(source, destStore));
320+
public Future<TemplateApiResult> orchestrateTemplateCopyFromSecondaryStores(long srcTemplateId, DataStore destStore) {
321+
Long dstZoneId = destStore.getScope().getScopeId();
322+
return submit(dstZoneId, new CopyTemplateFromSecondaryStorageTask(srcTemplateId, destStore));
309323
}
310324

311325
protected Pair<String, Boolean> migrateCompleted(Long destDatastoreId, DataStore srcDatastore, List<DataObject> files, MigrationPolicy migrationPolicy, int skipped) {
@@ -624,13 +638,13 @@ public DataObjectResult call() {
624638
}
625639
}
626640

627-
private class CopyTemplateTask implements Callable<TemplateApiResult> {
628-
private TemplateInfo sourceTmpl;
629-
private DataStore destStore;
630-
private String logid;
641+
private class CopyTemplateFromSecondaryStorageTask implements Callable<TemplateApiResult> {
642+
private final long srcTemplateId;
643+
private final DataStore destStore;
644+
private final String logid;
631645

632-
public CopyTemplateTask(TemplateInfo sourceTmpl, DataStore destStore) {
633-
this.sourceTmpl = sourceTmpl;
646+
CopyTemplateFromSecondaryStorageTask(long srcTemplateId, DataStore destStore) {
647+
this.srcTemplateId = srcTemplateId;
634648
this.destStore = destStore;
635649
this.logid = ThreadContext.get(LOGCONTEXTID);
636650
}
@@ -639,17 +653,16 @@ public CopyTemplateTask(TemplateInfo sourceTmpl, DataStore destStore) {
639653
public TemplateApiResult call() {
640654
ThreadContext.put(LOGCONTEXTID, logid);
641655
TemplateApiResult result;
642-
AsyncCallFuture<TemplateApiResult> future = templateService.copyTemplateToImageStore(sourceTmpl, destStore);
656+
long destZoneId = destStore.getScope().getScopeId();
657+
TemplateInfo sourceTmpl = templateDataFactory.getTemplate(srcTemplateId, DataStoreRole.Image);
643658
try {
644-
result = future.get();
645-
} catch (ExecutionException | InterruptedException e) {
646-
logger.warn("Exception while copying template [{}] from image store [{}] to image store [{}]: {}",
647-
sourceTmpl.getUniqueName(), sourceTmpl.getDataStore().getName(), destStore.getName(), e.toString());
659+
templateService.handleTemplateCopyFromSecondaryStores(srcTemplateId, destStore);
648660
result = new TemplateApiResult(sourceTmpl);
649-
result.setResult(e.getMessage());
661+
} finally {
662+
tryCleaningUpExecutor(destZoneId);
663+
ThreadContext.clearAll();
650664
}
651-
tryCleaningUpExecutor(destStore.getScope().getScopeId());
652-
ThreadContext.clearAll();
665+
653666
return result;
654667
}
655668
}

engine/schema/src/main/java/com/cloud/usage/dao/UsageDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public interface UsageDao extends GenericDao<UsageVO, Long> {
6262

6363
void saveUsageRecords(List<UsageVO> usageRecords);
6464

65-
void removeOldUsageRecords(int days);
65+
void expungeAllOlderThan(int days, long limitPerQuery);
6666

6767
UsageVO persistUsage(final UsageVO usage);
6868

0 commit comments

Comments
 (0)