Skip to content

Commit

Permalink
Merge pull request #219 from dulanjalidilmi/master
Browse files Browse the repository at this point in the history
Retrieve CApp artifacts via the management console
  • Loading branch information
SanojPunchihewa authored Aug 11, 2021
2 parents ea1fa77 + 5a6f739 commit d9d8f38
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.wso2.ei.dashboard.core.rest.model.AddUserRequest;
import org.wso2.ei.dashboard.core.rest.model.ArtifactUpdateRequest;
import org.wso2.ei.dashboard.core.rest.model.Artifacts;
import org.wso2.ei.dashboard.core.rest.model.CAppArtifacts;
import org.wso2.ei.dashboard.core.rest.model.DatasourceList;
import org.wso2.ei.dashboard.core.rest.model.Error;
import org.wso2.ei.dashboard.core.rest.model.GroupList;
Expand Down Expand Up @@ -220,6 +221,31 @@ public Response getCarbonApplicationsByNodeIds(
HttpUtils.setHeaders(responseBuilder);
return responseBuilder.build();
}

@GET
@Path("/{group-id}/nodes/{node-id}/capps/{capp-name}/artifacts")
@Produces({ "application/json" })
@Operation(summary = "Get artifact list of carbon application by node id", description = "",
tags={ "carbonApplications" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200",
description = "List of artifacts in carbon applications deployed in provided nodes",
content = @Content(schema = @Schema(implementation = CAppArtifacts.class))),
@ApiResponse(responseCode = "200", description = "Unexpected error",
content = @Content(schema = @Schema(implementation = Error.class)))
})
public Response getCarbonApplicationArtifactsByNodeIds(
@PathParam("group-id") @Parameter(description = "Group ID of the node") String groupId,
@PathParam("node-id") @Parameter(description = "Node ID") String nodeId,
@PathParam("capp-name") @Parameter(description = "Carbon application name") String cappName)
throws ManagementApiException {
CarbonAppsDelegate cappsDelegate = new CarbonAppsDelegate();
CAppArtifacts cAppArtifactList = cappsDelegate.getCAppArtifactList(groupId, nodeId, cappName);
Response.ResponseBuilder responseBuilder = Response.ok().entity(cAppArtifactList);
HttpUtils.setHeaders(responseBuilder);
return responseBuilder.build();
}

@GET
@Path("/{group-id}/connectors")
@Produces({ "application/json" })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
*/

package org.wso2.ei.dashboard.core.rest.model;

import java.util.ArrayList;
import java.util.List;
import org.wso2.ei.dashboard.core.rest.model.CAppArtifactsInner;
import javax.validation.constraints.*;
import javax.validation.Valid;


import io.swagger.annotations.*;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;


public class CAppArtifacts extends ArrayList<CAppArtifactsInner> {


@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CAppArtifacts cappArtifacts = (CAppArtifacts) o;
return true;
}

@Override
public int hashCode() {
return Objects.hash();
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CAppArtifacts {\n");
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
*/

package org.wso2.ei.dashboard.core.rest.model;

import javax.validation.constraints.*;
import javax.validation.Valid;


import io.swagger.annotations.*;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;


public class CAppArtifactsInner {
private @Valid String name = null;
private @Valid String type = null;

/**
**/
public CAppArtifactsInner name(String name) {
this.name = name;
return this;
}


@ApiModelProperty(value = "")
@JsonProperty("name")

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

/**
**/
public CAppArtifactsInner type(String type) {
this.type = type;
return this;
}


@ApiModelProperty(value = "")
@JsonProperty("type")

public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}


@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CAppArtifactsInner cappArtifactsInner = (CAppArtifactsInner) o;
return Objects.equals(name, cappArtifactsInner.name) &&
Objects.equals(type, cappArtifactsInner.type);
}

@Override
public int hashCode() {
return Objects.hash(name, type);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class CAppArtifactsInner {\n");

sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ private void processArtifacts(String accessToken, String artifactType, JsonObjec
for (JsonElement element : list) {
final String artifactName = element.getAsJsonObject().get("name").getAsString();
JsonObject artifactDetails = new JsonObject();
if (artifactType.equals(MESSAGE_STORES)) {
if (artifactType.equals(CARBON_APPLICATIONS)) {
artifactDetails.addProperty("name", artifactName);
artifactDetails.addProperty("version", element.getAsJsonObject().get("version").getAsString());
} else if (artifactType.equals(MESSAGE_STORES)) {
artifactDetails.addProperty("name", artifactName);
artifactDetails.addProperty("type", element.getAsJsonObject().get("type").getAsString());
artifactDetails.addProperty("size", element.getAsJsonObject().get("size").getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@

package org.wso2.ei.dashboard.micro.integrator.delegates;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.wso2.ei.dashboard.core.commons.Constants;
import org.wso2.ei.dashboard.core.commons.utils.HttpUtils;
import org.wso2.ei.dashboard.core.commons.utils.ManagementApiUtils;
import org.wso2.ei.dashboard.core.db.manager.DatabaseManager;
import org.wso2.ei.dashboard.core.db.manager.DatabaseManagerFactory;
import org.wso2.ei.dashboard.core.exception.ManagementApiException;
import org.wso2.ei.dashboard.core.rest.delegates.ArtifactDelegate;
import org.wso2.ei.dashboard.core.rest.model.Ack;
import org.wso2.ei.dashboard.core.rest.model.ArtifactUpdateRequest;
import org.wso2.ei.dashboard.core.rest.model.Artifacts;
import org.wso2.ei.dashboard.core.rest.model.CAppArtifacts;
import org.wso2.ei.dashboard.core.rest.model.CAppArtifactsInner;
import org.wso2.ei.dashboard.micro.integrator.commons.Utils;

import java.util.List;

Expand All @@ -45,6 +55,27 @@ public Artifacts getArtifactsList(String groupId, List<String> nodeList) {
return databaseManager.fetchArtifacts(Constants.CARBON_APPLICATIONS, groupId, nodeList);
}

public CAppArtifacts getCAppArtifactList(String groupId, String nodeId, String cAppName)
throws ManagementApiException {
log.debug("Fetching artifacts in carbon applications from management console");
String mgtApiUrl = ManagementApiUtils.getMgtApiUrl(groupId, nodeId);
String url = mgtApiUrl.concat("applications").concat("?").concat("carbonAppName").concat("=").concat(cAppName);

String accessToken = databaseManager.getAccessToken(groupId, nodeId);
CloseableHttpResponse httpResponse = Utils.doGet(groupId, nodeId, accessToken, url);
JsonObject jsonResponse = HttpUtils.getJsonResponse(httpResponse);
JsonArray artifacts = jsonResponse.getAsJsonArray("artifacts");
CAppArtifacts cAppArtifacts = new CAppArtifacts();
for (JsonElement artifact : artifacts) {
JsonObject jsonObject = artifact.getAsJsonObject();
CAppArtifactsInner cAppArtifact = new CAppArtifactsInner();
cAppArtifact.setName(jsonObject.get("name").getAsString());
cAppArtifact.setType(jsonObject.get("type").getAsString());
cAppArtifacts.add(cAppArtifact);
}
return cAppArtifacts;
}

@Override
public Ack updateArtifact(String groupId, ArtifactUpdateRequest request) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,44 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/groups/{group-id}/nodes/{node-id}/capps/{capp-name}/artifacts:
get:
tags:
- "carbonApplications"
summary: "Get artifact list of carbon application by node id"
operationId: "getCarbonApplicationArtifactsByNodeIds"
parameters:
- name: "group-id"
in: path
description: "Group ID of the node"
required: true
schema:
type: string
- name: "node-id"
in: path
description: "Node ID"
required: true
schema:
type: string
- name: "capp-name"
in: path
description: "Carbon application name"
required: true
schema:
type: string
responses:
200:
description: "List of artifacts in carbon applications deployed in provided nodes"
content:
application/json:
schema:
$ref: '#/components/schemas/CAppArtifacts'
default:
description: "Unexpected error"
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/groups/{group-id}/logs:
get:
tags:
Expand Down Expand Up @@ -1322,7 +1360,15 @@ components:
type: array
items:
$ref: '#/components/schemas/ArtifactDetails'

CAppArtifacts:
type: array
items:
type: object
properties:
name:
type: string
type:
type: string
ArtifactUpdateRequest:
type: object
properties:
Expand Down
Loading

0 comments on commit d9d8f38

Please sign in to comment.