Skip to content

Commit 8b0bb7b

Browse files
committed
assorted changes
- capabilities returns extensions path - provisioner refactor - payload cleanup in b/g - delete extension additional checks Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 8cbd28e commit 8b0bb7b

File tree

13 files changed

+183
-24
lines changed

13 files changed

+183
-24
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public class ApiConstants {
223223
public static final String EXTENSION = "extension";
224224
public static final String EXTENSION_ID = "extensionid";
225225
public static final String EXTENSION_NAME = "extensionname";
226+
public static final String EXTENSIONS_PATH = "extensionspath";
226227
public static final String FENCE = "fence";
227228
public static final String FETCH_LATEST = "fetchlatest";
228229
public static final String FILESYSTEM = "filesystem";

api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void execute() {
7373
response.setSharedFsVmMinCpuCount((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_CPU_COUNT));
7474
response.setSharedFsVmMinRamSize((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_RAM_SIZE));
7575
response.setInstanceLeaseEnabled((Boolean) capabilities.get(ApiConstants.INSTANCE_LEASE_ENABLED));
76+
response.setExtensionsPath((String)capabilities.get(ApiConstants.EXTENSIONS_PATH));
7677
response.setObjectName("capability");
7778
response.setResponseName(getCommandName());
7879
this.setResponseObject(response);

api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.response;
1818

19+
import org.apache.cloudstack.acl.RoleType;
1920
import org.apache.cloudstack.api.ApiConstants;
2021
import org.apache.cloudstack.api.BaseResponse;
2122

@@ -140,6 +141,10 @@ public class CapabilitiesResponse extends BaseResponse {
140141
@Param(description = "true if instance lease feature is enabled", since = "4.21.0")
141142
private Boolean instanceLeaseEnabled;
142143

144+
@SerializedName(ApiConstants.EXTENSIONS_PATH)
145+
@Param(description = "The path of the extensions directory", since = "4.21.0", authorized = {RoleType.Admin})
146+
private String extensionsPath;
147+
143148
public void setSecurityGroupsEnabled(boolean securityGroupsEnabled) {
144149
this.securityGroupsEnabled = securityGroupsEnabled;
145150
}
@@ -255,4 +260,8 @@ public void setSharedFsVmMinRamSize(Integer sharedFsVmMinRamSize) {
255260
public void setInstanceLeaseEnabled(Boolean instanceLeaseEnabled) {
256261
this.instanceLeaseEnabled = instanceLeaseEnabled;
257262
}
263+
264+
public void setExtensionsPath(String extensionsPath) {
265+
this.extensionsPath = extensionsPath;
266+
}
258267
}

engine/components-api/src/main/java/com/cloud/hypervisor/ExternalProvisioner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
public interface ExternalProvisioner extends Manager {
3535

36+
String getExtensionsPath();
37+
3638
String getExtensionEntryPoint(String relativeEntryPoint);
3739

3840
String getChecksumForExtensionEntryPoint(String extensionName, String relativeEntryPoint);

engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,6 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
101101
List<VMTemplateVO> listByIds(List<Long> ids);
102102

103103
List<Long> listIdsByTemplateTag(String tag);
104+
105+
List<Long> listIdsByExtensionId(long extensionId);
104106
}

engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,17 @@ public List<Long> listIdsByTemplateTag(String tag) {
837837
return customSearchIncludingRemoved(sc, null);
838838
}
839839

840+
@Override
841+
public List<Long> listIdsByExtensionId(long extensionId) {
842+
GenericSearchBuilder<VMTemplateVO, Long> sb = createSearchBuilder(Long.class);
843+
sb.selectFields(sb.entity().getId());
844+
sb.and("extensionId", sb.entity().getExtensionId(), SearchCriteria.Op.EQ);
845+
sb.done();
846+
SearchCriteria<Long> sc = sb.create();
847+
sc.setParameters("extensionId", extensionId);
848+
return customSearch(sc, null);
849+
}
850+
840851
@Override
841852
public boolean updateState(
842853
com.cloud.template.VirtualMachineTemplate.State currentState,

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/dao/ExtensionCustomActionDao.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
// under the License.
1717
package org.apache.cloudstack.framework.extensions.dao;
1818

19+
import java.util.List;
20+
1921
import com.cloud.utils.db.GenericDao;
2022
import org.apache.cloudstack.framework.extensions.vo.ExtensionCustomActionVO;
2123

2224
public interface ExtensionCustomActionDao extends GenericDao<ExtensionCustomActionVO, Long> {
23-
ExtensionCustomActionVO findByNameAndExtensionId(Long extensionId, String name);
25+
ExtensionCustomActionVO findByNameAndExtensionId(long extensionId, String name);
26+
List<Long> listIdsByExtensionId(long extensionId);
2427
}

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/dao/ExtensionCustomActionDaoImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
package org.apache.cloudstack.framework.extensions.dao;
1919

20+
import java.util.List;
21+
22+
import org.apache.cloudstack.framework.extensions.vo.ExtensionCustomActionVO;
23+
2024
import com.cloud.utils.db.GenericDaoBase;
25+
import com.cloud.utils.db.GenericSearchBuilder;
2126
import com.cloud.utils.db.SearchBuilder;
2227
import com.cloud.utils.db.SearchCriteria;
23-
import org.apache.cloudstack.framework.extensions.vo.ExtensionCustomActionVO;
2428

2529
public class ExtensionCustomActionDaoImpl extends GenericDaoBase<ExtensionCustomActionVO, Long> implements ExtensionCustomActionDao {
2630

@@ -34,11 +38,22 @@ public ExtensionCustomActionDaoImpl() {
3438
}
3539

3640
@Override
37-
public ExtensionCustomActionVO findByNameAndExtensionId(Long extensionId, String name) {
41+
public ExtensionCustomActionVO findByNameAndExtensionId(long extensionId, String name) {
3842
SearchCriteria<ExtensionCustomActionVO> sc = AllFieldSearch.create();
3943
sc.setParameters("extensionId", extensionId);
4044
sc.setParameters("name", name);
4145

4246
return findOneBy(sc);
4347
}
48+
49+
@Override
50+
public List<Long> listIdsByExtensionId(long extensionId) {
51+
GenericSearchBuilder<ExtensionCustomActionVO, Long> sb = createSearchBuilder(Long.class);
52+
sb.selectFields(sb.entity().getId());
53+
sb.and("extensionId", sb.entity().getExtensionId(), SearchCriteria.Op.EQ);
54+
sb.done();
55+
SearchCriteria<Long> sc = sb.create();
56+
sc.setParameters("extensionId", extensionId);
57+
return customSearch(sc, null);
58+
}
4459
}

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
public interface ExtensionsManager extends Manager {
5252

53+
String getExtensionsPath();
54+
5355
Extension createExtension(CreateExtensionCmd cmd);
5456

5557
boolean prepareExtensionEntryPointAcrossServers(Extension extension);

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImpl.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@
5757
import org.apache.cloudstack.context.CallContext;
5858
import org.apache.cloudstack.extension.CustomActionResultResponse;
5959
import org.apache.cloudstack.extension.Extension;
60-
import org.apache.cloudstack.extension.ExtensionHelper;
6160
import org.apache.cloudstack.extension.ExtensionCustomAction;
61+
import org.apache.cloudstack.extension.ExtensionHelper;
6262
import org.apache.cloudstack.extension.ExtensionResourceMap;
63+
import org.apache.cloudstack.framework.config.ConfigKey;
64+
import org.apache.cloudstack.framework.config.Configurable;
6365
import org.apache.cloudstack.framework.extensions.api.AddCustomActionCmd;
6466
import org.apache.cloudstack.framework.extensions.api.CreateExtensionCmd;
6567
import org.apache.cloudstack.framework.extensions.api.DeleteCustomActionCmd;
@@ -121,6 +123,7 @@
121123
import com.cloud.hypervisor.Hypervisor;
122124
import com.cloud.org.Cluster;
123125
import com.cloud.serializer.GsonHelper;
126+
import com.cloud.storage.dao.VMTemplateDao;
124127
import com.cloud.utils.Pair;
125128
import com.cloud.utils.component.ManagerBase;
126129
import com.cloud.utils.component.PluggableService;
@@ -138,7 +141,12 @@
138141
import com.cloud.vm.VmDetailConstants;
139142
import com.cloud.vm.dao.VMInstanceDao;
140143

141-
public class ExtensionsManagerImpl extends ManagerBase implements ExtensionsManager, ExtensionHelper, PluggableService {
144+
public class ExtensionsManagerImpl extends ManagerBase implements ExtensionsManager, ExtensionHelper, PluggableService, Configurable {
145+
146+
ConfigKey<Integer> EntryPointStateCheckInterval = new ConfigKey<>("Advanced", Integer.class,
147+
"extension.entrypoint.state.check.interval", "60",
148+
"Interval (in seconds) for checking entry-point state of extensions",
149+
false, ConfigKey.Scope.Global);
142150

143151
@Inject
144152
ExtensionDao extensionDao;
@@ -191,6 +199,9 @@ public class ExtensionsManagerImpl extends ManagerBase implements ExtensionsMana
191199
@Inject
192200
AlertManager alertManager;
193201

202+
@Inject
203+
VMTemplateDao templateDao;
204+
194205
private ScheduledExecutorService entryPointSyncCheckExecutor;
195206

196207
protected String getDefaultExtensionRelativeEntryPoint(String name) {
@@ -469,6 +480,18 @@ protected Map<String, Object> getExternalAccessDetails(Map<String, String> actio
469480
return externalDetails;
470481
}
471482

483+
protected void checkOrchestratorTemplates(Long extensionId) {
484+
List<Long> extensionTemplateIds = templateDao.listIdsByExtensionId(extensionId);
485+
if (CollectionUtils.isNotEmpty(extensionTemplateIds)) {
486+
throw new CloudRuntimeException("Orchestrator extension has associated templates, remove them to delete the extension");
487+
}
488+
}
489+
490+
@Override
491+
public String getExtensionsPath() {
492+
return externalProvisioner.getExtensionsPath();
493+
}
494+
472495
@Override
473496
@ActionEvent(eventType = EventTypes.EVENT_EXTENSION_CREATE, eventDescription = "creating extension")
474497
public Extension createExtension(CreateExtensionCmd cmd) {
@@ -701,6 +724,12 @@ public boolean deleteExtension(DeleteExtensionCmd cmd) {
701724
if (CollectionUtils.isNotEmpty(registeredResources)) {
702725
throw new CloudRuntimeException("Extension has associated resources, unregister them to delete the extension");
703726
}
727+
List<Long> customActionIds = extensionCustomActionDao.listIdsByExtensionId(extensionId);
728+
if (CollectionUtils.isNotEmpty(customActionIds)) {
729+
throw new CloudRuntimeException(String.format("Extension has %d custom actions, delete them to delete the extension",
730+
customActionIds.size()));
731+
}
732+
checkOrchestratorTemplates(extensionId);
704733

705734
boolean result = Transaction.execute((TransactionCallbackWithException<Boolean, CloudRuntimeException>) status -> {
706735
extensionDetailsDao.removeDetails(extensionId);
@@ -1413,8 +1442,8 @@ public Extension getExtensionForCluster(long clusterId) {
14131442

14141443
@Override
14151444
public boolean start() {
1416-
long syncCheckInitialDelay = 120;
1417-
long syncCheckInterval = 600;
1445+
long syncCheckInterval = EntryPointStateCheckInterval.value();
1446+
long syncCheckInitialDelay = Math.max(60, syncCheckInterval);
14181447
logger.debug("Scheduling extensions entrypoint sync check task with initial delay={}s and interval={}s",
14191448
syncCheckInitialDelay, syncCheckInterval);
14201449
entryPointSyncCheckExecutor.scheduleWithFixedDelay(new EntryPointSyncCheckWorker(),
@@ -1451,6 +1480,18 @@ public List<Class<?>> getCommands() {
14511480
return cmds;
14521481
}
14531482

1483+
@Override
1484+
public String getConfigComponentName() {
1485+
return ExtensionsManager.class.getSimpleName();
1486+
}
1487+
1488+
@Override
1489+
public ConfigKey<?>[] getConfigKeys() {
1490+
return new ConfigKey[]{
1491+
EntryPointStateCheckInterval
1492+
};
1493+
}
1494+
14541495
public class EntryPointSyncCheckWorker extends ManagedContextRunnable {
14551496

14561497
protected void checkExtensionEntryPointSync(Extension extension, List<ManagementServerHostVO> msHosts) {

0 commit comments

Comments
 (0)