Skip to content

Commit 2926bb4

Browse files
committed
Trigger management feature enrichment on CSAR upload
1 parent e762355 commit 2926bb4

File tree

8 files changed

+172
-111
lines changed

8 files changed

+172
-111
lines changed

org.opentosca.container.api/src/org/opentosca/container/api/controller/CsarController.java

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@
3434
import org.opentosca.container.api.dto.request.CsarTransformRequest;
3535
import org.opentosca.container.api.dto.request.CsarUploadRequest;
3636
import org.opentosca.container.api.service.CsarService;
37-
import org.opentosca.container.api.service.PlanService;
3837
import org.opentosca.container.api.util.ModelUtil;
3938
import org.opentosca.container.api.util.UriUtil;
4039
import org.opentosca.container.connector.winery.WineryConnector;
4140
import org.opentosca.container.control.IOpenToscaControlService;
4241
import org.opentosca.container.core.common.EntityExistsException;
43-
import org.opentosca.container.core.common.SystemException;
44-
import org.opentosca.container.core.common.UserException;
42+
import org.opentosca.container.core.common.Settings;
4543
import org.opentosca.container.core.engine.IToscaEngineService;
4644
import org.opentosca.container.core.model.csar.CSARContent;
4745
import org.opentosca.container.core.model.csar.id.CSARID;
@@ -198,6 +196,14 @@ private Response handleCsarUpload(final String filename, final InputStream is) {
198196

199197
final File file = this.csarService.storeTemporaryFile(filename, is);
200198

199+
final WineryConnector wc = new WineryConnector();
200+
201+
// perform management feature enrichment for the given CSAR
202+
if (Boolean.parseBoolean(Settings.OPENTOSCA_MANAGEMENT_FEATURE_ENRICHMENT)) {
203+
logger.debug("Management feature enrichment enabled. Trying to enrich given CSAR with available features...");
204+
wc.performManagementFeatureEnrichment(file);
205+
}
206+
201207
CSARID csarId;
202208

203209
try {
@@ -235,27 +241,22 @@ private Response handleCsarUpload(final String filename, final InputStream is) {
235241
}
236242

237243
// TODO this is such a brutal hack, won't go through reviews....
238-
final WineryConnector wc = new WineryConnector();
239-
boolean repoAvailable = wc.isWineryRepositoryAvailable();
240-
244+
final boolean repoAvailable = wc.isWineryRepositoryAvailable();
241245
final StringBuilder strB = new StringBuilder();
242246

243247
// quick and dirty parallel thread to upload the csar to the container
244248
// repository
245249
// This is needed for the state save feature
246-
Thread parallelUploadThread = new Thread(new Runnable() {
247-
@Override
248-
public void run() {
249-
if (wc.isWineryRepositoryAvailable()) {
250-
try {
251-
strB.append(wc.uploadCSAR(file, false));
252-
}
253-
catch (URISyntaxException e) {
254-
e.printStackTrace();
255-
}
256-
catch (IOException e) {
257-
e.printStackTrace();
258-
}
250+
final Thread parallelUploadThread = new Thread(() -> {
251+
if (wc.isWineryRepositoryAvailable()) {
252+
try {
253+
strB.append(wc.uploadCSAR(file, false));
254+
}
255+
catch (final URISyntaxException e1) {
256+
e1.printStackTrace();
257+
}
258+
catch (final IOException e2) {
259+
e2.printStackTrace();
259260
}
260261
}
261262
});
@@ -294,7 +295,6 @@ public void run() {
294295
return Response.serverError().build();
295296
}
296297

297-
298298
if (!success) {
299299
return Response.serverError().build();
300300
}
@@ -322,23 +322,24 @@ public Response deleteCsar(@ApiParam("ID of CSAR") @PathParam("csar") final Stri
322322

323323
return Response.noContent().build();
324324
}
325-
325+
326326
@POST
327327
@Path("/transform")
328328
@ApiOperation(value = "Transform this CSAR to a new CSAR")
329329
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
330330
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
331331
public Response transformCsar(@ApiParam(required = true) final CsarTransformRequest request) {
332-
333-
String sourceCsarName = request.getSourceCsarName();
334-
String targetCsarName = request.getTargetCsarName();
335-
336-
CSARID csarId = this.csarService.generateTransformationPlans(new CSARID(sourceCsarName), new CSARID(targetCsarName));
337-
338-
this.controlService.setDeploymentProcessStateStored(csarId);
332+
333+
final String sourceCsarName = request.getSourceCsarName();
334+
final String targetCsarName = request.getTargetCsarName();
335+
336+
final CSARID csarId =
337+
this.csarService.generateTransformationPlans(new CSARID(sourceCsarName), new CSARID(targetCsarName));
338+
339+
this.controlService.setDeploymentProcessStateStored(csarId);
339340
boolean success = this.controlService.invokeTOSCAProcessing(csarId);
340341

341-
342+
342343
if (success) {
343344
final List<QName> serviceTemplates =
344345
this.engineService.getToscaReferenceMapper().getServiceTemplateIDsContainedInCSAR(csarId);
@@ -351,15 +352,15 @@ public Response transformCsar(@ApiParam(required = true) final CsarTransformRequ
351352
success = false;
352353
}
353354
}
354-
}
355-
356-
if(success) {
355+
}
356+
357+
if (success) {
357358
return Response.ok().build();
358359
} else {
359360
return Response.serverError().build();
360361
}
361362
}
362-
363+
363364

364365

365366
public void setCsarService(final CsarService csarService) {

org.opentosca.container.api/src/org/opentosca/container/api/service/PlanService.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.LinkedHashMap;
88
import java.util.List;
99
import java.util.Map;
10+
import java.util.Objects;
1011
import java.util.stream.Collectors;
1112

1213
import javax.ws.rs.NotFoundException;
@@ -82,17 +83,10 @@ public List<TPlan> getPlansByType(final CSARID id, final PlanTypes... planTypes)
8283
}
8384

8485
public TPlan getPlan(final String name, final CSARID id) {
85-
86-
final List<TPlan> plans = getPlansByType(id, ALL_PLAN_TYPES);
87-
88-
for (final TPlan plan : plans) {
89-
if (plan.getId() != null && plan.getId().equalsIgnoreCase(name)) {
90-
return plan;
91-
}
92-
}
93-
return null;
86+
return getPlansByType(id, ALL_PLAN_TYPES).stream().filter(plan -> Objects.nonNull(plan.getId())
87+
&& plan.getId().equalsIgnoreCase(name)).findFirst().orElse(null);
9488
}
95-
89+
9690

9791

9892
public String invokePlan(final CSARID csarId, final QName serviceTemplate, final long serviceTemplateInstanceId,
@@ -131,11 +125,11 @@ public boolean hasPlan(final CSARID csarId, final PlanTypes[] planTypes, final S
131125
return false;
132126
}
133127

134-
135-
public PlanInstance getPlanInstanceByCorrelationId(String correlationId) {
136-
return this.planInstanceRepository.findByCorrelationId(correlationId);
128+
129+
public PlanInstance getPlanInstanceByCorrelationId(final String correlationId) {
130+
return this.planInstanceRepository.findByCorrelationId(correlationId);
137131
}
138-
132+
139133
/**
140134
* Gets the indicated plan instance and performs sanity checks insuring that the plan belongs to the
141135
* service template, the instance belongs to the plan, and belongs to the service template instance
@@ -282,10 +276,10 @@ public Response invokePlan(final String plan, final UriInfo uriInfo, final List<
282276
}
283277

284278
// set "meta" params
285-
for (TParameter param : parameters) {
279+
for (final TParameter param : parameters) {
286280
if (param.getName().equals(Interfaces.OPENTOSCA_DECLARATIVE_INTERFACE_STATE_FREEZE_MANDATORY_PARAM_ENDPOINT)
287281
&& param.getValue() != null && param.getValue().isEmpty()) {
288-
String containerRepoUrl = Settings.getSetting("org.opentosca.container.connector.winery.url");
282+
final String containerRepoUrl = Settings.getSetting("org.opentosca.container.connector.winery.url");
289283
param.setValue(containerRepoUrl);
290284
}
291285
}

org.opentosca.container.connector.winery/META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ Bundle-ClassPath: .
99
Export-Package: org.opentosca.container.connector.winery
1010
Import-Package: com.fasterxml.jackson.core;version="2.6.2",
1111
com.fasterxml.jackson.databind;version="2.6.2",
12+
org.apache.commons.io;version="2.2.0",
1213
org.apache.http;version="4.2.1",
1314
org.apache.http.client;version="4.2.0",
1415
org.apache.http.client.entity;version="4.2.0",
1516
org.apache.http.client.methods;version="4.2.0",
17+
org.apache.http.entity;version="4.3.3",
1618
org.apache.http.entity.mime;version="4.2.0",
1719
org.apache.http.entity.mime.content;version="4.2.0",
1820
org.apache.http.impl.client;version="4.2.0",

0 commit comments

Comments
 (0)