Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private RequestVariables() {
public static final String MTA_ID = "mtaId";
public static final String NAMESPACE = "namespace";
public static final String MTA_NAME = "name";
public static final String FORMAT = "format";

}

Expand Down Expand Up @@ -62,6 +63,8 @@ private Endpoints() {
}

public static final String MTA = "/{" + RequestVariables.MTA_ID + "}";
public static final String MTA_GRAPH = MTA + "/graph";
public static final String DESCRIPTOR_GRAPH = "/graph";
public static final String OPERATION = "/{" + PathVariables.OPERATION_ID + "}";
public static final String OPERATION_LOGS = OPERATION + "/logs";
public static final String OPERATION_LOG_CONTENT = OPERATION_LOGS + "/{" + PathVariables.LOG_ID + "}/content";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import org.cloudfoundry.multiapps.controller.api.model.Mta;
import org.cloudfoundry.multiapps.controller.api.model.MtaGraph;
import org.springframework.http.ResponseEntity;

public interface MtasApiService {
Expand All @@ -11,6 +12,12 @@ public interface MtasApiService {

ResponseEntity<Mta> getMta(String spaceGuid, String mtaId);

ResponseEntity<MtaGraph> getMtaGraph(String spaceGuid, String mtaId, String namespace);

ResponseEntity<MtaGraph> buildGraphFromDescriptor(String spaceGuid, String descriptorYaml);

ResponseEntity<String> buildGraphFromDescriptorAsDot(String spaceGuid, String descriptorYaml);

ResponseEntity<List<Mta>> getMtas(String spaceGuid, String mtaId, String namespace);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cloudfoundry.multiapps.controller.api.model;

import java.util.List;

import org.immutables.value.Value;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import io.swagger.annotations.ApiModelProperty;

@Value.Immutable
@JsonSerialize(as = ImmutableMtaGraph.class)
@JsonDeserialize(as = ImmutableMtaGraph.class)
public interface MtaGraph {

@ApiModelProperty
@JsonProperty("nodes")
List<MtaGraphNode> getNodes();

@ApiModelProperty
@JsonProperty("edges")
List<MtaGraphEdge> getEdges();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.cloudfoundry.multiapps.controller.api.model;

import org.immutables.value.Value;

import org.cloudfoundry.multiapps.common.Nullable;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import io.swagger.annotations.ApiModelProperty;

@Value.Immutable
@JsonSerialize(as = ImmutableMtaGraphEdge.class)
@JsonDeserialize(as = ImmutableMtaGraphEdge.class)
public interface MtaGraphEdge {

@ApiModelProperty
@JsonProperty("from")
String getFrom();

@ApiModelProperty
@JsonProperty("to")
String getTo();

@ApiModelProperty
@JsonProperty("type")
String getType();

@Nullable
@ApiModelProperty
@JsonProperty("name")
String getName();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.cloudfoundry.multiapps.controller.api.model;

import org.immutables.value.Value;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import io.swagger.annotations.ApiModelProperty;

@Value.Immutable
@JsonSerialize(as = ImmutableMtaGraphNode.class)
@JsonDeserialize(as = ImmutableMtaGraphNode.class)
public interface MtaGraphNode {

@ApiModelProperty
@JsonProperty("id")
String getId();

@ApiModelProperty
@JsonProperty("type")
String getType();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
import org.cloudfoundry.multiapps.controller.api.Constants.RequestVariables;
import org.cloudfoundry.multiapps.controller.api.Constants.Resources;
import org.cloudfoundry.multiapps.controller.api.model.Mta;
import org.cloudfoundry.multiapps.controller.api.model.MtaGraph;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
Expand Down Expand Up @@ -48,6 +52,23 @@ public ResponseEntity<Mta> getMta(@ApiParam(value = "GUID of space with mtas") @
return delegate.getMta(spaceGuid, mtaId);
}

@GetMapping(path = Endpoints.MTA_GRAPH, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Retrieve the dependency graph of a deployed MTA", notes = "Retrieves the module/resource dependency graph of a Multi-Target Application in a space", response = MtaGraph.class, authorizations = {
@Authorization(value = "oauth2", scopes = {

}) }, tags = {})
@ApiResponses(value = { @ApiResponse(code = 200, message = HttpResponses.OK, response = MtaGraph.class),
@ApiResponse(code = 401, message = HttpResponses.UNAUTHORIZED),
@ApiResponse(code = 403, message = HttpResponses.FORBIDDEN),
@ApiResponse(code = 404, message = HttpResponses.NOT_FOUND),
@ApiResponse(code = 500, message = HttpResponses.INTERNAL_SERVER_ERROR) })
public ResponseEntity<MtaGraph>
getMtaGraph(@ApiParam(value = "GUID of space with mtas") @PathVariable(PathVariables.SPACE_GUID) String spaceGuid,
@ApiParam(value = "mtaID of requested mta") @PathVariable(RequestVariables.MTA_ID) String mtaId,
@ApiParam(value = "Namespace of the MTA") @RequestParam(value = RequestVariables.NAMESPACE, required = false) String namespace) {
return delegate.getMtaGraph(spaceGuid, mtaId, namespace);
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Retrieve all deployed MTAs in a space", notes = "Retrieves all Multi-Target Applications in a space", response = Mta.class, responseContainer = "List", authorizations = {
@Authorization(value = "oauth2", scopes = {
Expand All @@ -62,4 +83,24 @@ public ResponseEntity<Mta> getMta(@ApiParam(value = "GUID of space with mtas") @
return delegate.getMtas(spaceGuid);
}

@PostMapping(path = Endpoints.DESCRIPTOR_GRAPH, consumes = "application/yaml", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Build dependency graph from a descriptor", notes = "Parses a supplied mtad.yaml and returns its module/resource dependency graph", response = MtaGraph.class, authorizations = {
@Authorization(value = "oauth2", scopes = {

}) }, tags = {})
@ApiResponses(value = { @ApiResponse(code = 200, message = HttpResponses.OK, response = MtaGraph.class),
@ApiResponse(code = 400, message = HttpResponses.BAD_REQUEST),
@ApiResponse(code = 401, message = HttpResponses.UNAUTHORIZED),
@ApiResponse(code = 403, message = HttpResponses.FORBIDDEN),
@ApiResponse(code = 500, message = HttpResponses.INTERNAL_SERVER_ERROR) })
public ResponseEntity<?>
buildGraphFromDescriptor(@ApiParam(value = "GUID of space with mtas") @PathVariable(PathVariables.SPACE_GUID) String spaceGuid,
@ApiParam(value = "mtad.yaml content") @RequestBody String descriptorYaml,
@ApiParam(value = "Output format: json (default) or dot") @RequestParam(value = RequestVariables.FORMAT, required = false) String format) {
if ("dot".equalsIgnoreCase(format)) {
return delegate.buildGraphFromDescriptorAsDot(spaceGuid, descriptorYaml);
}
return delegate.buildGraphFromDescriptor(spaceGuid, descriptorYaml);
}

}
155 changes: 155 additions & 0 deletions multiapps-controller-api/src/main/resources/mtarest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,87 @@ paths:
description: "Internal Server Error"
security:
- oauth2: []
/api/v1/spaces/{spaceGuid}/mtas/graph:
post:
summary: "Build dependency graph from a descriptor"
description: "Parses a supplied mtad.yaml and returns its module/resource dependency\
\ graph"
operationId: "buildGraphFromDescriptor"
consumes:
- "application/yaml"
produces:
- "application/json"
parameters:
- name: "spaceGuid"
in: "path"
description: "GUID of space with mtas"
required: true
type: "string"
- in: "body"
name: "body"
description: "mtad.yaml content"
required: false
schema:
type: "string"
- name: "format"
in: "query"
description: "Output format: json (default) or dot"
required: false
type: "string"
responses:
"200":
description: "OK"
schema:
$ref: "#/definitions/MtaGraph"
"400":
description: "Bad Request"
"401":
description: "Unauthorized"
"403":
description: "Forbidden"
"500":
description: "Internal Server Error"
security:
- oauth2: []
/api/v1/spaces/{spaceGuid}/mtas/{mtaId}/graph:
get:
summary: "Retrieve the dependency graph of a deployed MTA"
description: "Retrieves the module/resource dependency graph of a Multi-Target\
\ Application in a space"
operationId: "getMtaGraph"
produces:
- "application/json"
parameters:
- name: "spaceGuid"
in: "path"
description: "GUID of space with mtas"
required: true
type: "string"
- name: "mtaId"
in: "path"
description: "mtaID of requested mta"
required: true
type: "string"
- name: "namespace"
in: "query"
description: "Namespace of the MTA"
required: false
type: "string"
responses:
"200":
description: "OK"
schema:
$ref: "#/definitions/MtaGraph"
"401":
description: "Unauthorized"
"403":
description: "Forbidden"
"404":
description: "Not Found"
"500":
description: "Internal Server Error"
security:
- oauth2: []
/api/v1/spaces/{spaceGuid}/mtas:
get:
summary: "Retrieve all deployed MTAs in a space"
Expand Down Expand Up @@ -732,6 +813,43 @@ definitions:
uniqueItems: true
items:
type: "string"
MtaGraph:
type: "object"
properties:
nodes:
type: "array"
readOnly: true
items:
$ref: "#/definitions/MtaGraphNode"
edges:
type: "array"
readOnly: true
items:
$ref: "#/definitions/MtaGraphEdge"
MtaGraphEdge:
type: "object"
properties:
from:
type: "string"
readOnly: true
to:
type: "string"
readOnly: true
type:
type: "string"
readOnly: true
name:
type: "string"
readOnly: true
MtaGraphNode:
type: "object"
properties:
id:
type: "string"
readOnly: true
type:
type: "string"
readOnly: true
Operation:
type: "object"
properties:
Expand Down Expand Up @@ -789,6 +907,43 @@ definitions:
readOnly: true
additionalProperties:
type: "object"
MtaGraph:
type: "object"
properties:
nodes:
type: "array"
readOnly: true
items:
$ref: "#/definitions/MtaGraphNode"
edges:
type: "array"
readOnly: true
items:
$ref: "#/definitions/MtaGraphEdge"
MtaGraphEdge:
type: "object"
properties:
from:
type: "string"
readOnly: true
to:
type: "string"
readOnly: true
type:
type: "string"
readOnly: true
name:
type: "string"
readOnly: true
MtaGraphNode:
type: "object"
properties:
id:
type: "string"
readOnly: true
type:
type: "string"
readOnly: true
ProcessType:
type: "object"
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class MtaMetadataAnnotations {
public static final String MTA_NAMESPACE = "mta_namespace";
public static final String MTA_MODULE = "mta_module";
public static final String MTA_MODULE_PUBLIC_PROVIDED_DEPENDENCIES = "mta_module_provided_dependencies";
public static final String MTA_MODULE_REQUIRED_DEPENDENCIES = "mta_module_required_dependencies";
public static final String MTA_MODULE_BOUND_SERVICES = "mta_bound_services";

public static final String MTA_RESOURCE = "mta_resource";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ public DeployedMtaApplication parseDeployedMtaApplication(CloudApplication appli
String moduleName = parseNameAttribute(metadataAnnotations, MtaMetadataAnnotations.MTA_MODULE);
List<String> providedDependencies = parseModuleProvidedDependencies(application.getName(), metadataAnnotations,
MtaMetadataAnnotations.MTA_MODULE_PUBLIC_PROVIDED_DEPENDENCIES);
List<String> requiredDependencies = parseList(metadataAnnotations, MtaMetadataAnnotations.MTA_MODULE_REQUIRED_DEPENDENCIES);
List<String> boundMtaServices = parseList(metadataAnnotations, MtaMetadataAnnotations.MTA_MODULE_BOUND_SERVICES);
return ImmutableDeployedMtaApplication.builder()
.from(application)
.moduleName(moduleName)
.boundMtaServices(boundMtaServices)
.providedDependencyNames(providedDependencies)
.requiredDependencyNames(requiredDependencies)
.build();
}

Expand Down
Loading
Loading