Commit d494d033 authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

Using EE monitoring REST interface

parent df134b00
......@@ -15,11 +15,48 @@
*/
package eu.chorevolution.idm.choremocks.ee;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
public interface EnactmentEngineApi {
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
Response listEEVirtualMachines(String enactmentEngineId);
Response listChoreographyVirtualMachines(String enactmentEngineId, String choreographyId);
}
@Path("/v1/monitoring")
@Api("Monitoring")
public interface MonitoringApi {
@GET
@Path("/ee")
@Produces(MediaType.APPLICATION_JSON)
Response getEngineStatus();
@GET
@Path("/ee/vm")
@Produces(MediaType.APPLICATION_JSON)
Response getEngineVirtualMachines();
@GET
@Path("/chor/{choreographyId}")
@Produces(MediaType.APPLICATION_JSON)
Response getChorStatus(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to monitor", required = true)
@PathParam("choreographyId") String choreographyId
);
@GET
@Path("/chor/{choreographyId}/vm")
@Produces(MediaType.APPLICATION_JSON)
Response getChorVirtualMachines(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to monitor", required = true)
@PathParam("choreographyId") String choreographyId
);
}
\ No newline at end of file
/*
* Copyright 2017 The CHOReVOLUTION project.
*
* Licensed 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 eu.chorevolution.idm.choremocks.ee;
import eu.chorevolution.idm.common.to.EnactmentEngineStatusTO;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import javax.ws.rs.core.Response;
public class MonitoringResource implements MonitoringApi {
@Override
public Response getEngineStatus() {
EnactmentEngineStatusTO enactmentEngineStatusTO = new EnactmentEngineStatusTO();
enactmentEngineStatusTO.setKey("dummyKey");
enactmentEngineStatusTO.setRamUsage(4880);
enactmentEngineStatusTO.setRamTotal(13336);
enactmentEngineStatusTO.setStorageTotal(3024);
enactmentEngineStatusTO.setStorageUsage(628);
enactmentEngineStatusTO.setCpuUsageRatio(36.0);
enactmentEngineStatusTO.setVirtualMachinesCount(4);
return Response.ok(enactmentEngineStatusTO).build();
}
@Override
public Response getEngineVirtualMachines() {
VirtualMachineInfoTO info1 = new VirtualMachineInfoTO();
info1.setKey("vm001");
info1.setSysOp("Ubuntu 16.10");
info1.setCpuCount(4);
info1.setCpuUsageRatio(30.5);
info1.setRamUsage(1500);
info1.setRamTotal(4096);
info1.setStorageUsage(100);
info1.setStorageTotal(1000);
info1.setIsChoreography(true);
info1.setIsLoadBalancer(false);
VirtualMachineInfoTO info2 = new VirtualMachineInfoTO();
info2.setKey("vm002");
info2.setSysOp("Ubuntu 16.10");
info2.setCpuCount(2);
info2.setCpuUsageRatio(51);
info2.setRamUsage(400);
info2.setRamTotal(1048);
info2.setStorageUsage(100);
info2.setStorageTotal(512);
info2.setIsChoreography(false);
info2.setIsLoadBalancer(true);
VirtualMachineInfoTO info3 = new VirtualMachineInfoTO();
info3.setKey("vm003");
info3.setSysOp("Ubuntu 16.10");
info3.setCpuCount(4);
info3.setCpuUsageRatio(26.5);
info3.setRamUsage(2230);
info3.setRamTotal(4096);
info3.setStorageUsage(88);
info3.setStorageTotal(512);
info3.setIsChoreography(false);
info3.setIsLoadBalancer(true);
VirtualMachineInfoTO info4 = new VirtualMachineInfoTO();
info4.setKey("vm004");
info4.setSysOp("Ubuntu 16.10");
info4.setCpuCount(4);
info4.setCpuUsageRatio(44);
info4.setRamUsage(750);
info4.setRamTotal(4096);
info4.setStorageUsage(340);
info4.setStorageTotal(1000);
info4.setIsChoreography(true);
info4.setIsLoadBalancer(false);
VirtualMachineInfoTO[] result = new VirtualMachineInfoTO[4];
result[0] = info1;
result[1] = info2;
result[2] = info3;
result[3] = info4;
if(result == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Error while acting on EE").build();
}
return Response.ok(result).build();
}
@Override
public Response getChorStatus(final String choreographyId) {
if (choreographyId == null || choreographyId.isEmpty()) {
return Response.serverError().entity("chorID cannot be blank").build();
}
EnactmentEngineStatusTO enactmentEngineStatusTO = new EnactmentEngineStatusTO();
enactmentEngineStatusTO.setKey("dummyKey");
enactmentEngineStatusTO.setRamUsage(1900);
enactmentEngineStatusTO.setRamTotal(5144);
enactmentEngineStatusTO.setStorageTotal(1512);
enactmentEngineStatusTO.setStorageUsage(200);
enactmentEngineStatusTO.setCpuUsageRatio(37.0);
enactmentEngineStatusTO.setVirtualMachinesCount(2);
return Response.ok(enactmentEngineStatusTO).build();
}
@Override
public Response getChorVirtualMachines(final String choreographyId) {
if (choreographyId == null || choreographyId.isEmpty()) {
return Response.serverError().entity("chorID cannot be blank").build();
}
VirtualMachineInfoTO info1 = new VirtualMachineInfoTO();
info1.setKey("vm001");
info1.setSysOp("Ubuntu 16.10");
info1.setCpuCount(4);
info1.setCpuUsageRatio(30.5);
info1.setRamUsage(1500);
info1.setRamTotal(4096);
info1.setStorageUsage(100);
info1.setStorageTotal(1000);
info1.setIsChoreography(true);
info1.setIsLoadBalancer(false);
VirtualMachineInfoTO info2 = new VirtualMachineInfoTO();
info2.setKey("vm002");
info2.setSysOp("Ubuntu 16.10");
info2.setCpuCount(2);
info2.setCpuUsageRatio(51);
info2.setRamUsage(400);
info2.setRamTotal(1048);
info2.setStorageUsage(100);
info2.setStorageTotal(512);
info2.setIsChoreography(false);
info2.setIsLoadBalancer(true);
VirtualMachineInfoTO[] result = new VirtualMachineInfoTO[2];
result[0] = info1;
result[1] = info2;
if(result == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Choreografy not found for choreographyId: " + choreographyId).build();
}
return Response.ok(result).build();
}
}
......@@ -17,9 +17,8 @@ package org.apache.syncope.client.console.panels;
import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import eu.chorevolution.idm.common.to.EnactmentEngineStatusTO;
import java.io.Serializable;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.client.console.commons.Constants;
......@@ -44,8 +43,6 @@ public class ChoreographyEEResourcesPanel extends Panel {
private final AnyObjectTO enactmentEngine;
private final EEStatisticBundle bundle;
private final BaseModal<Serializable> utilityModal = new BaseModal<>("resizeEEModal");
private final ChoreographyTO choreography;
......@@ -61,8 +58,11 @@ public class ChoreographyEEResourcesPanel extends Panel {
this.restClient = new ChoreographyRestClient();
this.choreography = restClient.getChoreography(choreographyId);
this.enactmentEngine = restClient.getChoreographyEE(choreography.getId());
this.bundle = new EEStatisticBundle(
restClient.getChoreographyVmList(enactmentEngine.getKey(), choreography.getId()));
EnactmentEngineStatusTO ee = restClient.getChoreographyEEStatus(choreographyId);
double ramPercentage = (ee.getRamUsage() / Float.valueOf(ee.getRamTotal())) * 100;
double storagePercentage = (ee.getStorageUsage() / Float.valueOf(ee.getStorageTotal())) * 100;
add(utilityModal);
add(new Label("eeName", enactmentEngine.getName()));
......@@ -70,16 +70,15 @@ public class ChoreographyEEResourcesPanel extends Panel {
RepeatingView resourcesOverview = new RepeatingView("resourceWidget");
resourcesOverview.add(new ResourceWidget(
resourcesOverview.newChildId(),
"bg-yellow", bundle.virtualMachines, "Virtual Machines", "fa fa-cube"));
"bg-yellow", ee.getVirtualMachinesCount(), "Virtual Machines", "fa fa-cube"));
resourcesOverview.add(new ResourceWidget(
resourcesOverview.newChildId(), "bg-red", "CPU utilization", bundle.percentageCPU, "fa fa-cogs"));
resourcesOverview.newChildId(), "bg-red", "CPU utilization", ee.getCpuUsageRatio(), "fa fa-cogs"));
resourcesOverview.add(new ResourceWidget(
resourcesOverview.newChildId(),
"bg-green", bundle.usedRam, bundle.totalRam, "RAM utilization", bundle.percentageRam, "MB", ""));
resourcesOverview.newChildId(), "bg-green", ee.getRamUsage(), ee.getRamTotal(),
"RAM utilization", ramPercentage, "MB", ""));
resourcesOverview.add(new ResourceWidget(
resourcesOverview.newChildId(), "bg-aqua",
bundle.usedStorage, bundle.totalStorage,
"Storage occupancy", bundle.percentageStorage, "GB", "fa fa-database"));
resourcesOverview.newChildId(), "bg-aqua", ee.getStorageUsage(), ee.getStorageTotal(),
"Storage occupancy", storagePercentage, "GB", "fa fa-database"));
add(resourcesOverview);
ChoreographyActionsPanel actionsPanel = new ChoreographyActionsPanel("actionsPanel");
......@@ -178,55 +177,5 @@ public class ChoreographyEEResourcesPanel extends Panel {
add(new ChoreographyVMDirectoryPanel(
"virtualMachinesList", pageRef, enactmentEngine.getKey(), choreography.getId()));
}
private class EEStatisticBundle implements Serializable {
private static final long serialVersionUID = 3856101339158216754L;
private int virtualMachines;
private int cpus;
private double percentageCPU;
private int usedRam;
private int totalRam;
private double percentageRam;
private int usedStorage;
private int totalStorage;
private double percentageStorage;
EEStatisticBundle(final List<VirtualMachineInfoTO> vms) {
this.virtualMachines = 0;
this.cpus = 0;
this.usedRam = 0;
this.totalRam = 0;
this.usedStorage = 0;
this.totalStorage = 0;
double cpuUtilization = 0;
for (VirtualMachineInfoTO vm: vms) {
this.virtualMachines ++;
this.cpus += vm.getCpuNumber();
this.usedRam += vm.getUsedRam();
this.totalRam += vm.getTotalRam();
this.usedStorage += vm.getUsedStorage();
this.totalStorage += vm.getTotalStorage();
cpuUtilization += vm.getCpuNumber() * vm.getCpuUtilization();
}
this.percentageCPU = Math.round(100 * (cpuUtilization / Float.valueOf(cpus))) / 100d;
this.percentageRam = Math.round(10000 * (usedRam / Float.valueOf(totalRam))) / 100d;
this.percentageStorage = Math.round(10000 * (usedStorage / Float.valueOf(totalStorage)) / 100d);
}
}
}
......@@ -36,6 +36,7 @@ import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulato
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
......@@ -97,25 +98,39 @@ public class ChoreographyVMDirectoryPanel extends DirectoryPanel<
protected List<IColumn<VirtualMachineInfoTO, String>> getColumns() {
final List<IColumn<VirtualMachineInfoTO, String>> columns = new ArrayList<>();
columns.add(new PropertyColumn<>(new ResourceModel("ipAddress", "IP"), "IP", "ipAddress"));
columns.add(new PropertyColumn<>(new ResourceModel("hostname", "Hostname"), "Hostname", "hostname"));
columns.add(new PropertyColumn<>(new ResourceModel("os"), "OS", "os"));
columns.add(new PropertyColumn<>(new ResourceModel("type", "Type"), "Type", "type"));
//columns.add(new PropertyColumn<>(new ResourceModel("ipAddress", "IP"), "IP", "ipAddress"));
//columns.add(new PropertyColumn<>(new ResourceModel("hostname", "Hostname"), "Hostname", "hostname"));
columns.add(new PropertyColumn<>(new ResourceModel("sysOp", "OS"), "OS", "sysOp"));
//columns.add(new PropertyColumn<>(new ResourceModel("type", "Type"), "Type", "type"));
columns.add(new PropertyColumn<>(new ResourceModel(
"choreography", "Deployed Choreography"), "Deployed Choreography", "choreography"));
columns.add(new AbstractColumn<VirtualMachineInfoTO, String>(new ResourceModel("", "Type")) {
private static final long serialVersionUID = -5860164518940274921L;
@Override
public void populateItem(final Item<ICellPopulator<VirtualMachineInfoTO>> item, final String componentId,
final IModel<VirtualMachineInfoTO> model) {
if (model.getObject().getIsChoreography()) {
item.add(new Label(componentId, "Choreography"));
} else {
item.add(new Label(componentId, "Load Balancer"));
}
}
});
//columns.add(new PropertyColumn<>(new ResourceModel(
// "choreography", "Deployed Choreography"), "Deployed Choreography", "choreography"));
columns.add(new PropertyColumn<>(new ResourceModel("cpuNumber", "CPU"), "CPU", "cpuNumber"));
columns.add(new PropertyColumn<>(new ResourceModel("cpuCount", "CPU"), "CPU", "cpuCount"));
columns.add(new PropertyColumn<>(new ResourceModel(
"cpuUtilization", "CPU Utilization (%)"), "CPU Utilization (%)", "cpuUtilization"));
"cpuUsageRatio", "CPU Utilization (%)"), "CPU Utilization (%)", "cpuUsageRatio"));
columns.add(new PropertyColumn<>(new ResourceModel(
"usedRam", "Used Memory (MB)"), "Used Memory (MB)", "usedRam"));
"ramUsage", "Used Memory (MB)"), "Used Memory (MB)", "ramUsage"));
columns.add(new PropertyColumn<>(new ResourceModel(
"totalRam", "Total Memory (MB)"), "Total Memory (MB)", "totalRam"));
"ramTotal", "Total Memory (MB)"), "Total Memory (MB)", "ramTotal"));
columns.add(new PropertyColumn<>(new ResourceModel(
"usedStorage", "Used Storage (GB)"), "Used Storage (GB)", "usedStorage"));
"storageUsage", "Used Storage (GB)"), "Used Storage (GB)", "storageUsage"));
columns.add(new PropertyColumn<>(new ResourceModel(
"totalStorage", "Total Storage (GB)"), "Total Storage (GB)", "totalStorage"));
"storageTotal", "Total Storage (GB)"), "Total Storage (GB)", "storageTotal"));
columns.add(new AbstractColumn<VirtualMachineInfoTO, String>(new ResourceModel("", "")) {
......@@ -182,7 +197,7 @@ public class ChoreographyVMDirectoryPanel extends DirectoryPanel<
@Override
public int compare(final VirtualMachineInfoTO o1, final VirtualMachineInfoTO o2) {
return o1.getId().compareTo(o2.getId());
return o1.getKey().compareTo(o2.getKey());
}
}
......
......@@ -22,72 +22,73 @@ import eu.chorevolution.idm.common.to.OperationDataTO;
import eu.chorevolution.idm.common.to.ChoreographyInstanceTO;
import eu.chorevolution.idm.common.to.ChoreographyTO;
import eu.chorevolution.idm.common.to.CoordinationDelegateTO;
import eu.chorevolution.idm.common.to.EnactmentEngineStatusTO;
import eu.chorevolution.idm.common.to.ServiceTO;
import eu.chorevolution.idm.common.to.VirtualMachineInfoTO;
import eu.chorevolution.idm.common.types.ChoreographyAction;
import java.util.List;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.rest.api.service.ChoreographyService;
import org.apache.syncope.common.rest.api.service.ConsoleInterfaceService;
import org.apache.syncope.common.rest.api.service.MonitorInterfaceService;
public class ChoreographyRestClient extends BaseRestClient {
private static final long serialVersionUID = -2018208424159468912L;
public List<ChoreographyInstanceTO> instanceList(final String choreographyId) {
return getService(ConsoleInterfaceService.class).instanceList(choreographyId);
return getService(MonitorInterfaceService.class).instanceList(choreographyId);
}
public List<CoordinationDelegateTO> cdList(final String instanceId) {
return getService(ConsoleInterfaceService.class).cdList(instanceId);
return getService(MonitorInterfaceService.class).cdList(instanceId);
}
public List<ServiceTO> instanceServiceList(final String instanceId) {
return getService(ConsoleInterfaceService.class).instanceServiceList(instanceId);
return getService(MonitorInterfaceService.class).instanceServiceList(instanceId);
}
public List<ServiceTO> choreographyServiceList(final String choreographyId) {
return getService(ConsoleInterfaceService.class).choreographyServiceList(choreographyId);
return getService(MonitorInterfaceService.class).choreographyServiceList(choreographyId);
}
public List<OperationDataTO> operationList(
final String choreographyInstancePK,
final String cdName) {
return getService(ConsoleInterfaceService.class).operationList(choreographyInstancePK, cdName);
return getService(MonitorInterfaceService.class).operationList(choreographyInstancePK, cdName);
}
public ChoreographyTO getChoreography(final String choreographyId) {
return getService(ConsoleInterfaceService.class).getChoreography(choreographyId);
return getService(MonitorInterfaceService.class).getChoreography(choreographyId);
}
public ChoreographyInstanceTO getChoreographyInstance(final String choreographyInstancePK) {
return getService(ConsoleInterfaceService.class).getChoreographyInstance(choreographyInstancePK);
return getService(MonitorInterfaceService.class).getChoreographyInstance(choreographyInstancePK);
}
public CoordinationDelegateTO getCD(final String choreographyInstancePK, final String cdName) {
return getService(ConsoleInterfaceService.class).getCd(choreographyInstancePK, cdName);
return getService(MonitorInterfaceService.class).getCd(choreographyInstancePK, cdName);
}
public ServiceTO getService(final String choreographyInstancePK, final String serviceName) {
return getService(ConsoleInterfaceService.class).getService(choreographyInstancePK, serviceName);
return getService(MonitorInterfaceService.class).getService(choreographyInstancePK, serviceName);
}
public Double getAverageInstanceExecutionTime(final String choreographyId) {
return getService(ConsoleInterfaceService.class).getAverageInstanceExecutionTime(choreographyId);
return getService(MonitorInterfaceService.class).getAverageInstanceExecutionTime(choreographyId);
}
public List<AVGCoordinationDelegateTO> averageCdList(final String choreographyId) {
return getService(ConsoleInterfaceService.class).averageCdList(choreographyId);
return getService(MonitorInterfaceService.class).averageCdList(choreographyId);
}
public List<AVGServiceTO> averageServiceList(final String choreographyId) {
return getService(ConsoleInterfaceService.class).averageServiceList(choreographyId);
return getService(MonitorInterfaceService.class).averageServiceList(choreographyId);
}
public List<AVGOperationDataTO> averageOperationList(
final String choreographyId,
final String cdName) {
return getService(ConsoleInterfaceService.class).averageOperationList(choreographyId, cdName);
return getService(MonitorInterfaceService.class).averageOperationList(choreographyId, cdName);
}
public void deleteChoreography(final String choreographyId) {
......@@ -95,7 +96,7 @@ public class ChoreographyRestClient extends BaseRestClient {
}
public void deleteInstance(final String choreographyInstancePK) {
getService(ConsoleInterfaceService.class).deleteInstance(choreographyInstancePK);
getService(MonitorInterfaceService.class).deleteInstance(choreographyInstancePK);
}
public void startChoreography(final String choreographyId) {
......@@ -127,14 +128,14 @@ public class ChoreographyRestClient extends BaseRestClient {
return getService(ChoreographyService.class).getEnactmentEngine(choreographyId);
}
public EnactmentEngineStatusTO getChoreographyEEStatus(final String choreographyId) {
return getService(MonitorInterfaceService.class).getChoreographyEEStatus(choreographyId);
}
public List<VirtualMachineInfoTO> getChoreographyVmList(
final String enactmentEngineKey,
final String choreographyId) {
return getService(ChoreographyService.class).getChoreographyVmList(enactmentEngineKey, choreographyId);
return getService(MonitorInterfaceService.class).getChoreographyVmList(enactmentEngineKey, choreographyId);
}
public List<VirtualMachineInfoTO> getEEVmList(
final String enactmentEngineKey) {
return getService(ChoreographyService.class).getEEVmList(enactmentEngineKey);
}
}
/*
* Copyright 2017 The CHOReVOLUTION project.
*
* Licensed 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 eu.chorevolution.idm.common.to;
import org.apache.syncope.common.lib.AbstractBaseBean;
public class EnactmentEngineStatusTO extends AbstractBaseBean {
private static final long serialVersionUID = -3983719350936183516L;
private String key;
private double cpuUsageRatio;