Skip to content

Commit

Permalink
Merge pull request #140 from OpenTOSCA/feature/planmeasurement
Browse files Browse the repository at this point in the history
Feature/planmeasurement
  • Loading branch information
nyuuyn authored Jun 16, 2020
2 parents 40218e5 + 335e1ce commit 14161b2
Show file tree
Hide file tree
Showing 94 changed files with 2,873 additions and 487 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,6 @@ buildNumber.properties
!.vscode/launch.json
!.vscode/extensions.json

# End of https://www.gitignore.io/api/java,maven,eclipse,intellij,visualstudiocode
# End of https://www.gitignore.io/api/java,maven,eclipse,intellij,visualstudiocode
/org.opentosca.container.product/config.ini
/org.opentosca.container.product/org.opentosca.container.product

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.opentosca.container.connector.winery.WineryConnector;
import org.opentosca.container.control.IOpenToscaControlService;
import org.opentosca.container.core.common.EntityExistsException;
import org.opentosca.container.core.common.SystemException;
import org.opentosca.container.core.common.UserException;
import org.opentosca.container.core.engine.IToscaEngineService;
import org.opentosca.container.core.model.csar.CSARContent;
import org.opentosca.container.core.model.csar.id.CSARID;
Expand Down Expand Up @@ -162,7 +164,18 @@ public Response uploadCsar(@FormDataParam(value = "enrichment") final String app

logger.info("Uploading new CSAR file \"{}\", size {}", file.getFileName(), file.getSize());

return handleCsarUpload(file.getFileName(), is, applyEnrichment);
try {
return handleCsarUpload(file.getFileName(), is, applyEnrichment);
}
catch (SystemException e) {
e.printStackTrace();
return Response.serverError().entity(e).build();
}
catch (UserException e) {

e.printStackTrace();
return Response.serverError().entity(e).build();
}

}

Expand Down Expand Up @@ -197,7 +210,8 @@ public Response uploadCsar(@ApiParam(required = true) final CsarUploadRequest re
}


private Response handleCsarUpload(final String filename, final InputStream is, final String applyEnrichment) {
private Response handleCsarUpload(final String filename, final InputStream is,
final String applyEnrichment) throws SystemException, UserException {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,71 +38,112 @@
@Path("/situationsapi")
public class SituationsController {

@Context
UriInfo uriInfo;
@Context
UriInfo uriInfo;

private InstanceService instanceService;
private CsarService csarService;
private InstanceService instanceService;
private CsarService csarService;

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/situations")
public Response getSituations() {
final SituationListDTO dto = new SituationListDTO();
this.instanceService.getSituations().forEach(x -> dto.add(SituationDTO.Converter.convert(x)));
;
return Response.ok(dto).build();
}
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/situations")
public Response getSituations() {
final SituationListDTO dto = new SituationListDTO();
this.instanceService.getSituations().forEach(x -> dto.add(SituationDTO.Converter.convert(x)));;
return Response.ok(dto).build();
}

@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/situations/{situation}")
public Response updateSituation(@PathParam("situation") final Long situationId, final SituationDTO situation) {
final Situation sit = this.instanceService.getSituation(situation.getId());
@PUT
@Consumes({MediaType.TEXT_PLAIN})
@Path("/situations/{situation}/active")
public Response updateSituationActivity(@PathParam("situation") final Long situationId, final String body) {
final Situation sit = this.instanceService.getSituation(situationId);

sit.setActive(situation.getActive());
sit.setEventProbability(situation.getEventProbability());
sit.setEventTime(situation.getEventTime());
boolean active = false;

this.instanceService.updateSituation(sit);
if (body.equalsIgnoreCase("true") || body.equalsIgnoreCase("false")) {
active = Boolean.valueOf(body);
} else {
return Response.notAcceptable(null).build();
}

final URI instanceURI = UriUtil.generateSelfURI(this.uriInfo);

return Response.ok(instanceURI).build();
}

@PUT
@Consumes({ MediaType.TEXT_PLAIN })
@Path("/situations/{situation}/active")
public Response updateSituationActivity(@PathParam("situation") final Long situationId, final String body) {
final Situation sit = this.instanceService.getSituation(situationId);
sit.setActive(active);

boolean active = false;
this.instanceService.updateSituation(sit);

if (body.equalsIgnoreCase("true") || body.equalsIgnoreCase("false")) {
active = Boolean.valueOf(body);
} else {
return Response.notAcceptable(null).build();
}
final URI instanceURI = UriUtil.generateSelfURI(this.uriInfo);

sit.setActive(active);
return Response.ok(instanceURI).build();
}

this.instanceService.updateSituation(sit);
@POST
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/situations")
public Response createSituation(final SituationDTO situation) {
final Situation sit =
this.instanceService.createNewSituation(situation.getThingId(), situation.getSituationTemplateId(), situation.getActive(), situation.getEventProbability(), situation.getEventTime());
final URI instanceURI = UriUtil.generateSubResourceURI(this.uriInfo, sit.getId().toString(), false);

final URI instanceURI = UriUtil.generateSelfURI(this.uriInfo);
return Response.ok(instanceURI).build();
}

return Response.ok(instanceURI).build();
}
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/situations/{situation}")
public Response getSituation(@PathParam("situation") final Long situationId) {
return Response.ok(SituationDTO.Converter.convert(this.instanceService.getSituation(situationId))).build();
}

@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/triggers")
public Response getSituationTriggers() {
final SituationTriggerListDTO dto;
try {
dto = new SituationTriggerListDTO();
this.instanceService.getSituationTriggers().forEach(x -> dto.add(SituationTriggerDTO.Converter.convert(x)));
}
catch (final Exception e) {
e.printStackTrace();
return Response.serverError().build();
}
return Response.ok(dto).build();
}

@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/triggers/{situationtrigger}")
public Response getSituationTrigger(@PathParam("situationtrigger") final Long situationTriggerId) {
return Response.ok(SituationTriggerDTO.Converter.convert(this.instanceService.getSituationTrigger(situationTriggerId)))
.build();
}

@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/triggers/{situationtrigger}/{situationtriggerinstance}")
public Response getSituationTriggerInstance(@PathParam("situationtrigger") final Long situationTriggerId,
@PathParam("situationtriggerinstance") final Long situationTriggerInstanceId) {
return Response.ok(SituationTriggerInstanceDTO.Converter.convert(this.instanceService.getSituationTriggerInstance(situationTriggerInstanceId)))
.build();
}

@POST

@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/situations")
public Response createSituation(final SituationDTO situation) {
final Situation sit = this.instanceService.createNewSituation(situation.getThingId(),
situation.getSituationTemplateId(), situation.getActive(), situation.getEventProbability(),
situation.getEventTime());
final URI instanceURI = UriUtil.generateSubResourceURI(this.uriInfo, sit.getId().toString(), false);
@Path("/situations/{situation}")
public Response updateSituation(@PathParam("situation") final Long situationId, final SituationDTO situation) {
final Situation sit = this.instanceService.getSituation(situation.getId());

sit.setActive(situation.getActive());
sit.setEventProbability(situation.getEventProbability());
sit.setEventTime(situation.getEventTime());

this.instanceService.updateSituation(sit);

final URI instanceURI = UriUtil.generateSelfURI(this.uriInfo);

return Response.ok(instanceURI).build();
}
Expand All @@ -121,28 +162,6 @@ public Response deleteSituation(@PathParam("situation") final Long situationId)
}
}

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/situations/{situation}")
public Response getSituation(@PathParam("situation") final Long situationId) {
return Response.ok(SituationDTO.Converter.convert(this.instanceService.getSituation(situationId))).build();
}

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/triggers")
public Response getSituationTriggers() {
final SituationTriggerListDTO dto;
try {
dto = new SituationTriggerListDTO();
this.instanceService.getSituationTriggers().forEach(x -> dto.add(SituationTriggerDTO.Converter.convert(x)));
} catch (final Exception e) {
e.printStackTrace();
return Response.serverError().build();
}
return Response.ok(dto).build();
}

@POST
@Path("/triggers")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Expand Down Expand Up @@ -183,38 +202,17 @@ public Response createSituationTrigger(final SituationTriggerDTO situationTrigge
.forEach(x -> inputs.add(new SituationTriggerProperty(x.getName(), x.getValue(), x.getType())));


final SituationTrigger sitTrig = this.instanceService.createNewSituationTrigger(sits, this.csarService.findById(situationTrigger.getCsarId()).getCSARID(),
situationTrigger.isOnActivation(), situationTrigger.isSingleInstance(), serviceInstance, nodeInstance,
situationTrigger.getInterfaceName(), situationTrigger.getOperationName(), inputs, eventProbability,
eventTime);

final SituationTrigger sitTrig = this.instanceService.createNewSituationTrigger(sits, this.csarService.findById(situationTrigger.getCsarId()).getCSARID(), situationTrigger.isOnActivation(), situationTrigger.isSingleInstance(),serviceInstance, nodeInstance, situationTrigger.getInterfaceName(), situationTrigger.getOperationName(), inputs, eventProbability, eventTime);
final URI instanceURI = UriUtil.generateSubResourceURI(this.uriInfo, sitTrig.getId().toString(), false);
return Response.ok(instanceURI).build();
}

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/triggers/{situationtrigger}")
public Response getSituationTrigger(@PathParam("situationtrigger") final Long situationTriggerId) {
return Response
.ok(SituationTriggerDTO.Converter.convert(this.instanceService.getSituationTrigger(situationTriggerId)))
.build();
}

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/triggers/{situationtrigger}/{situationtriggerinstance}")
public Response getSituationTriggerInstance(@PathParam("situationtrigger") final Long situationTriggerId,
@PathParam("situationtriggerinstance") final Long situationTriggerInstanceId) {
return Response.ok(SituationTriggerInstanceDTO.Converter
.convert(this.instanceService.getSituationTriggerInstance(situationTriggerInstanceId))).build();
}

public void setInstanceService(final InstanceService instanceService) {
this.instanceService = instanceService;
}

public void setCsarService(final CsarService csarService) {
this.csarService = csarService;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.opentosca.container.core.tosca.extension.TParameter;
import org.opentosca.container.core.tosca.extension.TParameterDTO;
import org.opentosca.container.core.tosca.extension.TPlanDTO;
import org.opentosca.container.core.tosca.model.TBoolean;
import org.opentosca.container.core.tosca.model.TPlan;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Expand Down Expand Up @@ -50,6 +51,8 @@ public class PlanDTO extends ResourceSupport {
@XmlElement(name = "PlanModelReference")
private String planModelReference;

@XmlElement(name = "CalculatedWCET")
private long calculatedWCET;

public PlanDTO() {

Expand All @@ -65,6 +68,7 @@ public PlanDTO(final TPlan plan) {
this.outputParameters.addAll(plan.getOutputParameters().getOutputParameter().stream()
.map(p -> new TParameter(p)).collect(Collectors.toList()));
this.planModelReference = plan.getPlanModelReference().getReference();
this.calculatedWCET = plan.getCalculatedWCET();
}

public String getId() {
Expand Down Expand Up @@ -128,6 +132,14 @@ public void setPlanModelReference(final String planModelReference) {
this.planModelReference = planModelReference;
}

@ApiModelProperty(name = "calculated_wcet")
public long getCalculatedWCET() {
return this.calculatedWCET;
}

public void setCalculatedWCET(final long calculatedWCET) {
this.calculatedWCET = calculatedWCET;
}

public static final class Converter {

Expand All @@ -138,6 +150,7 @@ public static TPlanDTO convert(final PlanDTO object) {
plan.setName(object.getName());
plan.setPlanLanguage(object.getPlanLanguage());
plan.setPlanType(object.getPlanType());
plan.setCalculatedWCET(object.getCalculatedWCET());

final TPlanDTO.InputParameters inputParameters = new TPlanDTO.InputParameters();
for (final TParameter param : object.getInputParameters()) {
Expand All @@ -161,6 +174,7 @@ public static PlanDTO convert(final TPlanDTO object) {
plan.setName(object.getName());
plan.setPlanLanguage(object.getPlanLanguage());
plan.setPlanType(object.getPlanType());
plan.setCalculatedWCET(object.getCalculatedWCET());

final List<TParameter> inputParameters = object.getInputParameters().getInputParameter().stream().map(p -> {
final TParameter parameter = new TParameter();
Expand Down
Loading

0 comments on commit 14161b2

Please sign in to comment.