1919
2020package org .apache .cloudstack .framework .extensions .manager ;
2121
22+ import java .util .ArrayList ;
23+ import java .util .Collections ;
24+ import java .util .List ;
25+ import java .util .Map ;
26+
27+ import javax .inject .Inject ;
28+
29+ import org .apache .cloudstack .api .ApiConstants ;
30+ import org .apache .cloudstack .api .response .ExtensionCustomActionResponse ;
31+ import org .apache .cloudstack .api .response .ExtensionResourceMapResponse ;
32+ import org .apache .cloudstack .api .response .ExtensionResponse ;
33+ import org .apache .cloudstack .extension .CustomActionResponse ;
34+ import org .apache .cloudstack .framework .extensions .api .AddCustomActionCmd ;
35+ import org .apache .cloudstack .framework .extensions .api .CreateExtensionCmd ;
36+ import org .apache .cloudstack .framework .extensions .api .DeleteCustomActionCmd ;
37+ import org .apache .cloudstack .framework .extensions .api .DeleteExtensionCmd ;
38+ import org .apache .cloudstack .framework .extensions .api .ListCustomActionCmd ;
39+ import org .apache .cloudstack .framework .extensions .api .ListExtensionsCmd ;
40+ import org .apache .cloudstack .framework .extensions .api .RegisterExtensionCmd ;
41+ import org .apache .cloudstack .framework .extensions .api .RunCustomActionCmd ;
42+ import org .apache .cloudstack .framework .extensions .dao .ExtensionCustomActionDao ;
43+ import org .apache .cloudstack .framework .extensions .dao .ExtensionCustomActionDetailsDao ;
44+ import org .apache .cloudstack .framework .extensions .dao .ExtensionDao ;
45+ import org .apache .cloudstack .framework .extensions .dao .ExtensionDetailsDao ;
46+ import org .apache .cloudstack .framework .extensions .dao .ExtensionResourceMapDao ;
47+ import org .apache .cloudstack .framework .extensions .dao .ExtensionResourceMapDetailsDao ;
48+ import org .apache .cloudstack .framework .extensions .vo .ExtensionCustomActionDetailsVO ;
49+ import org .apache .cloudstack .framework .extensions .vo .ExtensionCustomActionVO ;
50+ import org .apache .cloudstack .framework .extensions .vo .ExtensionDetailsVO ;
51+ import org .apache .cloudstack .framework .extensions .vo .ExtensionResourceMapDetailsVO ;
52+ import org .apache .cloudstack .framework .extensions .vo .ExtensionResourceMapVO ;
53+ import org .apache .cloudstack .framework .extensions .vo .ExtensionVO ;
54+ import org .apache .commons .collections .CollectionUtils ;
55+
2256import com .cloud .agent .AgentManager ;
2357import com .cloud .agent .api .RunCustomActionAnswer ;
2458import com .cloud .agent .api .RunCustomActionCommand ;
2862import com .cloud .exception .AgentUnavailableException ;
2963import com .cloud .exception .InvalidParameterValueException ;
3064import com .cloud .exception .OperationTimedoutException ;
65+ import com .cloud .extension .Extension ;
3166import com .cloud .extension .ExtensionCustomAction ;
3267import com .cloud .host .HostVO ;
3368import com .cloud .host .dao .HostDao ;
3469import com .cloud .host .dao .HostDetailsDao ;
3570import com .cloud .hypervisor .ExternalProvisioner ;
71+ import com .cloud .org .Cluster ;
3672import com .cloud .utils .Pair ;
73+ import com .cloud .utils .component .ManagerBase ;
74+ import com .cloud .utils .component .PluggableService ;
3775import com .cloud .utils .db .Filter ;
3876import com .cloud .utils .db .SearchBuilder ;
3977import com .cloud .utils .db .SearchCriteria ;
4078import com .cloud .utils .exception .CloudRuntimeException ;
4179import com .cloud .vm .VMInstanceVO ;
4280import com .cloud .vm .VirtualMachine ;
4381import com .cloud .vm .dao .VMInstanceDao ;
44- import org .apache .cloudstack .api .ApiConstants ;
45- import org .apache .cloudstack .api .response .ExtensionCustomActionResponse ;
46- import org .apache .cloudstack .extension .CustomActionResponse ;
47- import org .apache .cloudstack .framework .extensions .api .CreateExtensionCmd ;
48- import org .apache .cloudstack .framework .extensions .api .DeleteCustomActionCmd ;
49- import org .apache .cloudstack .framework .extensions .api .DeleteExtensionCmd ;
50- import org .apache .cloudstack .framework .extensions .api .ListCustomActionCmd ;
51- import org .apache .cloudstack .framework .extensions .api .ListExtensionsCmd ;
52- import org .apache .cloudstack .framework .extensions .api .AddCustomActionCmd ;
53- import org .apache .cloudstack .framework .extensions .api .RunCustomActionCmd ;
54- import com .cloud .utils .component .ManagerBase ;
55- import com .cloud .utils .component .PluggableService ;
56- import org .apache .cloudstack .framework .extensions .api .RegisterExtensionCmd ;
57- import org .apache .cloudstack .framework .extensions .dao .ExtensionCustomActionDao ;
58- import org .apache .cloudstack .framework .extensions .dao .ExtensionCustomActionDetailsDao ;
59- import org .apache .cloudstack .framework .extensions .dao .ExtensionResourceMapDao ;
60- import org .apache .cloudstack .framework .extensions .dao .ExtensionResourceMapDetailsDao ;
61- import org .apache .cloudstack .framework .extensions .dao .ExtensionDao ;
62- import org .apache .cloudstack .framework .extensions .dao .ExtensionDetailsDao ;
63- import org .apache .cloudstack .api .response .ExtensionResourceMapResponse ;
64- import org .apache .cloudstack .api .response .ExtensionResponse ;
65- import com .cloud .extension .Extension ;
66- import org .apache .cloudstack .framework .extensions .vo .ExtensionCustomActionDetailsVO ;
67- import org .apache .cloudstack .framework .extensions .vo .ExtensionCustomActionVO ;
68- import org .apache .cloudstack .framework .extensions .vo .ExtensionResourceMapDetailsVO ;
69- import org .apache .cloudstack .framework .extensions .vo .ExtensionResourceMapVO ;
70- import org .apache .cloudstack .framework .extensions .vo .ExtensionVO ;
71- import org .apache .cloudstack .framework .extensions .vo .ExtensionDetailsVO ;
72- import org .apache .commons .collections .CollectionUtils ;
73-
74- import javax .inject .Inject ;
75- import java .util .ArrayList ;
76- import java .util .Collections ;
77- import java .util .List ;
78- import java .util .Map ;
7982
8083public class ExtensionsManagerImpl extends ManagerBase implements ExtensionsManager , PluggableService {
8184
@@ -132,7 +135,7 @@ public Extension createExtension(CreateExtensionCmd cmd) {
132135 ExtensionVO extension = new ExtensionVO ();
133136 extension .setName (name );
134137 extension .setType (type );
135- String scriptPath = String . format ( externalProvisioner .getScriptPath (), name );
138+ String scriptPath = externalProvisioner .getExtensionScriptPath ( name );
136139 extension .setScript (scriptPath );
137140 ExtensionVO savedExtension = extensionDao .persist (extension );
138141
@@ -180,7 +183,7 @@ public List<ExtensionResponse> listExtensions(ListExtensionsCmd cmd) {
180183 for (ExtensionVO extension : result .first ()) {
181184 Map <String , String > details = extensionDetailsDao .listDetailsKeyPairs (extension .getId ());
182185 ExtensionResponse response = new ExtensionResponse (extension .getName (), extension .getType (), extension .getUuid (), details );
183- String scriptPath = String . format ( externalProvisioner .getScriptPath (), extension .getName ());
186+ String scriptPath = externalProvisioner .getExtensionScriptPath ( extension .getName ());
184187 response .setScriptPath (scriptPath );
185188
186189 List <ExtensionResourceMapVO > extensionResourceMapVOS = extensionResourceMapDao .listByExtensionId (extension .getId ());
@@ -210,21 +213,22 @@ public ExtensionResponse registerExtensionWithResource(RegisterExtensionCmd cmd)
210213 Long extensionId = cmd .getExtensionId ();
211214 String resourceType = cmd .getResourceType ();
212215 if ("CLUSTER" .equalsIgnoreCase (resourceType )) {
213- return registerExtensionWithCluster (resourceId , extensionId , resourceType , cmd .getExternalDetails ());
216+ return registerExtensionWithCluster (resourceId , extensionId , cmd .getExternalDetails ());
214217 } else {
215218 throw new CloudRuntimeException ("Currently only cluster can be used to register an extension of type Orchestrator" );
216219 }
217220 }
218221
219222 @ Override
220- public ExtensionResponse registerExtensionWithCluster (String resourceId , Long extensionId , String resourceType , Map <String , String > externalDetails ) {
223+ public ExtensionResponse registerExtensionWithCluster (String resourceId , Long extensionId , Map <String , String > externalDetails ) {
224+ final String resourceType = Cluster .class .getSimpleName ();
221225 ClusterVO cluster = clusterDao .findByUuid (resourceId );
222226 ExtensionResourceMapVO existing = extensionResourceMapDao .findByResourceIdAndType (cluster .getId (), resourceType );
223227 if (existing != null ) {
224228 throw new CloudRuntimeException ("Extension already registered with this resource" );
225229 }
226230
227- ExtensionResourceMapVO extensionMap = new ExtensionResourceMapVO ();
231+ ExtensionResourceMapVO extensionMap = new ExtensionResourceMapVO (extensionId , cluster . getId (), resourceType );
228232 extensionMap .setExtensionId (extensionId );
229233 extensionMap .setResourceId (cluster .getId ());
230234 extensionMap .setResourceType (resourceType );
@@ -247,11 +251,11 @@ public ExtensionResponse registerExtensionWithCluster(String resourceId, Long ex
247251 clusterDetailsDao .persist (cluster .getId (), externalDetails );
248252
249253 ExtensionResponse response = new ExtensionResponse (extension .getName (), extension .getType (), extension .getUuid (), details );
250- String scriptPath = String . format ( externalProvisioner .getScriptPath (), extension .getName ());
254+ String scriptPath = externalProvisioner .getExtensionScriptPath ( extension .getName ());
251255 response .setScriptPath (scriptPath );
252256
253- ExtensionResourceMapVO extensionResourceMapVO = extensionResourceMapDao .findByResourceIdAndType (cluster .getId (), "cluster" );
254- ExtensionResourceMapResponse resourceResponse = new ExtensionResourceMapResponse (extension .getUuid (), cluster .getUuid (), "cluster" );
257+ ExtensionResourceMapVO extensionResourceMapVO = extensionResourceMapDao .findByResourceIdAndType (cluster .getId (), resourceType );
258+ ExtensionResourceMapResponse resourceResponse = new ExtensionResourceMapResponse (extension .getUuid (), cluster .getUuid (), resourceType );
255259
256260 Map <String , String > resourceMapDetails = extensionResourceMapDetailsDao .listDetailsKeyPairs (extensionResourceMapVO .getId ());
257261 resourceResponse .setDetails (resourceMapDetails );
0 commit comments