ui: Run diagnostics API UI integration for system VMs and VR (#2833)

- Run diagnostics API UI integration for system VMs and VR
- Added event type to Action event
This commit is contained in:
Dingane Hlaluku 2018-09-18 12:29:22 +02:00 committed by Rohit Yadav
parent e559154a41
commit 0b6eafc0f6
6 changed files with 428 additions and 20 deletions

View File

@ -105,6 +105,7 @@ public class EventTypes {
public static final String EVENT_ROUTER_REBOOT = "ROUTER.REBOOT";
public static final String EVENT_ROUTER_HA = "ROUTER.HA";
public static final String EVENT_ROUTER_UPGRADE = "ROUTER.UPGRADE";
public static final String EVENT_ROUTER_DIAGNOSTICS = "ROUTER.DIAGNOSTICS";
// Console proxy
public static final String EVENT_PROXY_CREATE = "PROXY.CREATE";
@ -113,6 +114,7 @@ public class EventTypes {
public static final String EVENT_PROXY_STOP = "PROXY.STOP";
public static final String EVENT_PROXY_REBOOT = "PROXY.REBOOT";
public static final String EVENT_PROXY_HA = "PROXY.HA";
public static final String EVENT_PROXY_DIAGNOSTICS = "PROXY.DIAGNOSTICS";
// VNC Console Events
public static final String EVENT_VNC_CONNECT = "VNC.CONNECT";
@ -266,6 +268,7 @@ public class EventTypes {
public static final String EVENT_SSVM_STOP = "SSVM.STOP";
public static final String EVENT_SSVM_REBOOT = "SSVM.REBOOT";
public static final String EVENT_SSVM_HA = "SSVM.HA";
public static final String EVENT_SSVM_DIAGNOSTICS = "SSVM.DIAGNOSTICS";
// Service Offerings
public static final String EVENT_SERVICE_OFFERING_CREATE = "SERVICE.OFFERING.CREATE";
@ -571,6 +574,9 @@ public class EventTypes {
public static final String EVENT_TEMPLATE_DIRECT_DOWNLOAD_FAILURE = "TEMPLATE.DIRECT.DOWNLOAD.FAILURE";
public static final String EVENT_ISO_DIRECT_DOWNLOAD_FAILURE = "ISO.DIRECT.DOWNLOAD.FAILURE";
// Diagnostics Events
public static final String EVENT_SYSTEM_VM_DIAGNOSTICS = "SYSTEM.VM.DIAGNOSTICS";
static {
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@ -599,6 +605,7 @@ public class EventTypes {
entityEventDetails.put(EVENT_ROUTER_REBOOT, VirtualRouter.class);
entityEventDetails.put(EVENT_ROUTER_HA, VirtualRouter.class);
entityEventDetails.put(EVENT_ROUTER_UPGRADE, VirtualRouter.class);
entityEventDetails.put(EVENT_ROUTER_DIAGNOSTICS, VirtualRouter.class);
entityEventDetails.put(EVENT_PROXY_CREATE, VirtualMachine.class);
entityEventDetails.put(EVENT_PROXY_DESTROY, VirtualMachine.class);
@ -607,6 +614,7 @@ public class EventTypes {
entityEventDetails.put(EVENT_PROXY_REBOOT, VirtualMachine.class);
entityEventDetails.put(EVENT_ROUTER_HA, VirtualMachine.class);
entityEventDetails.put(EVENT_PROXY_HA, VirtualMachine.class);
entityEventDetails.put(EVENT_PROXY_DIAGNOSTICS, VirtualMachine.class);
entityEventDetails.put(EVENT_VNC_CONNECT, "VNC");
entityEventDetails.put(EVENT_VNC_DISCONNECT, "VNC");
@ -727,6 +735,7 @@ public class EventTypes {
entityEventDetails.put(EVENT_SSVM_STOP, VirtualMachine.class);
entityEventDetails.put(EVENT_SSVM_REBOOT, VirtualMachine.class);
entityEventDetails.put(EVENT_SSVM_HA, VirtualMachine.class);
entityEventDetails.put(EVENT_SSVM_DIAGNOSTICS, VirtualMachine.class);
// Service Offerings
entityEventDetails.put(EVENT_SERVICE_OFFERING_CREATE, ServiceOffering.class);
@ -964,6 +973,7 @@ public class EventTypes {
entityEventDetails.put(EVENT_TEMPLATE_DIRECT_DOWNLOAD_FAILURE, VirtualMachineTemplate.class);
entityEventDetails.put(EVENT_ISO_DIRECT_DOWNLOAD_FAILURE, "Iso");
entityEventDetails.put(EVENT_SYSTEM_VM_DIAGNOSTICS, VirtualMachine.class);
}
public static String getEntityForEvent(String eventName) {

View File

@ -16,15 +16,20 @@
// under the License.
package org.apache.cloudstack.api.command.admin.diagnostics;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.vm.VirtualMachine;
import java.util.Collections;
import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.api.ACL;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiArgValidator;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
@ -36,9 +41,11 @@ import org.apache.cloudstack.diagnostics.DiagnosticsType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import java.util.Collections;
import java.util.Map;
import com.cloud.event.EventTypes;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.vm.VirtualMachine;
@APICommand(name = RunDiagnosticsCmd.APINAME, responseObject = RunDiagnosticsResponse.class, entityType = {VirtualMachine.class},
responseHasSensitiveInfo = false,
@ -46,7 +53,7 @@ import java.util.Map;
description = "Execute network-utility command (ping/arping/tracert) on system VMs remotely",
authorized = {RoleType.Admin},
since = "4.12.0.0")
public class RunDiagnosticsCmd extends BaseCmd {
public class RunDiagnosticsCmd extends BaseAsyncCmd {
private static final Logger LOGGER = Logger.getLogger(RunDiagnosticsCmd.class);
public static final String APINAME = "runDiagnostics";
@ -56,6 +63,7 @@ public class RunDiagnosticsCmd extends BaseCmd {
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@ACL(accessType = SecurityChecker.AccessType.OperateEntry)
@Parameter(name = ApiConstants.TARGET_ID, type = CommandType.UUID, required = true, entityType = SystemVmResponse.class,
validations = {ApiArgValidator.PositiveNumber},
description = "The ID of the system VM instance to diagnose")
@ -116,6 +124,34 @@ public class RunDiagnosticsCmd extends BaseCmd {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
public String getEventType() {
VirtualMachine.Type vmType = _entityMgr.findById(VirtualMachine.class, getId()).getType();
String eventType = "";
switch (vmType) {
case ConsoleProxy:
eventType = EventTypes.EVENT_PROXY_DIAGNOSTICS;
break;
case SecondaryStorageVm:
eventType = EventTypes.EVENT_SSVM_DIAGNOSTICS;
break;
case DomainRouter:
eventType = EventTypes.EVENT_ROUTER_DIAGNOSTICS;
break;
}
return eventType;
}
@Override
public ApiCommandJobType getInstanceType() {
return ApiCommandJobType.SystemVm;
}
@Override
public String getEventDescription() {
return "Executing diagnostics on system vm: " + this._uuidMgr.getUuid(VirtualMachine.class, getId());
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
RunDiagnosticsResponse response = new RunDiagnosticsResponse();

View File

@ -17,9 +17,18 @@
// under the License.
package org.apache.cloudstack.diagnostics;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.inject.Inject;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.routing.NetworkElementCommand;
import com.cloud.event.ActionEvent;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.utils.component.ManagerBase;
@ -34,12 +43,6 @@ import org.apache.cloudstack.api.command.admin.diagnostics.RunDiagnosticsCmd;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class DiagnosticsServiceImpl extends ManagerBase implements PluggableService, DiagnosticsService {
private static final Logger LOGGER = Logger.getLogger(DiagnosticsServiceImpl.class);
@ -53,6 +56,7 @@ public class DiagnosticsServiceImpl extends ManagerBase implements PluggableServ
private NetworkOrchestrationService networkManager;
@Override
@ActionEvent(eventType = EventTypes.EVENT_SYSTEM_VM_DIAGNOSTICS, eventDescription = "running diagnostics on system vm", async = true)
public Map<String, String> runDiagnosticsCommand(final RunDiagnosticsCmd cmd) {
final Long vmId = cmd.getId();
final String cmdType = cmd.getType().getValue();

View File

@ -12862,6 +12862,14 @@ div.ui-dialog div.autoscaler div.field-group div.form-container form div.form-it
background-position: -168px -613px;
}
.diagnostics .icon {
background-position: -165px -122px;
}
.diagnostics:hover .icon {
background-position: -165px -704px;
}
.enableOutOfBandManagement .icon {
background-position: -138px -65px;
}

View File

@ -276,6 +276,7 @@ var dictionary = {
"label.action.restore.instance.processing":"Restoring Instance....",
"label.action.revert.snapshot":"Revert to Snapshot",
"label.action.revert.snapshot.processing":"Reverting to Snapshot...",
"label.action.run.diagnostics":"Run Diagnostics",
"label.action.secure.host":"Provision Host Security Keys",
"label.action.start.instance":"Start Instance",
"label.action.start.instance.processing":"Starting Instance....",
@ -1484,6 +1485,9 @@ var dictionary = {
"label.rule.number":"Rule Number",
"label.rule.number.short": "#Rule",
"label.rules":"Rules",
"label.run.diagnostics.type":"Type",
"label.run.diagnostics.destination":"Destination",
"label.run.diagnostics.extra":"Extra Arguments",
"label.running.vms":"Running VMs",
"label.s3.access_key":"Access Key",
"label.s3.bucket":"Bucket",
@ -2103,6 +2107,9 @@ var dictionary = {
"message.desc.zone":"A zone is the largest organizational unit in CloudStack, and it typically corresponds to a single datacenter. Zones provide physical isolation and redundancy. A zone consists of one or more pods (each of which contains hosts and primary storage servers) and a secondary storage server which is shared by all pods in the zone.",
"message.detach.disk":"Are you sure you want to detach this disk?",
"message.detach.iso.confirm":"Please confirm that you want to detach the ISO from this virtual instance.",
"message.diagnostics.exitcode":"exitcode: var",
"message.diagnostics.stderr":"stderr: var",
"message.diagnostics.stdout":"stdout: var",
"message.disable.account":"Please confirm that you want to disable this account. By disabling the account, all users for this account will no longer have access to their cloud resources. All running virtual machines will be immediately shut down.",
"message.disable.snapshot.policy":"You have successfully disabled your current snapshot policy.",
"message.disable.user":"Please confirm that you would like to disable this user.",

View File

@ -3840,6 +3840,91 @@
}
},
diagnostics: {
label: 'label.action.run.diagnostics',
messages: {
notification: function (args) {
return 'label.action.run.diagnostics';
},
complete: function(args) {
var exitcode = _l('message.diagnostics.exitcode');
exitcode = exitcode.replace('var', args.exitcode);
var stderr = _l('message.diagnostics.stderr');
stderr = stderr.replace('var', args.stderr);
var stdout = _l('message.diagnostics.stdout');
stdout = stdout.replace('var', args.stdout);
var msg = "<div style='text-align: left; overflow-y: auto'>" + exitcode + "<br><br>" + stderr + "<br><br>" + stdout + "</div>";
return msg;
}
},
createForm: {
title: 'label.action.run.diagnostics',
desc: '',
fields: {
type: {
label: 'label.run.diagnostics.type',
validation: {
required: true
},
select: function (args) {
var items = [];
items.push({
id: "ping",
description: "Ping"
});
items.push({
id: "traceroute",
description: "Traceroute"
});
items.push({
id: "arping",
description: "Arping"
});
args.response.success({
data: items
});
}
},
destination: {
label: 'label.run.diagnostics.destination',
validation: {
required: true
}
},
extra: {
label: 'label.run.diagnostics.extra'
}
}
},
action: function (args) {
$.ajax({
url: createURL("runDiagnostics&targetid=" + args.context.systemVMs[0].id + "&ipaddress=" + args.data.destination + "&type=" + args.data.type + "&params=" + args.data.extra),
dataType: "json",
async: true,
success: function(json) {
var jid = json.rundiagnosticsresponse.jobid;
args.response.success({
_custom: {
jobId : jid,
getUpdatedItem: function (json) {
return json.queryasyncjobresultresponse.jobresult.diagnostics;
},
getActionFilter: function(){
return systemvmActionfilter;
}
}
});
}
}); //end ajax
},
notification: {
poll: pollAsyncJobResult
}
},
viewConsole: {
label: 'label.view.console',
action: {
@ -8857,6 +8942,91 @@
}
},
diagnostics: {
label: 'label.action.run.diagnostics',
messages: {
notification: function (args) {
return 'label.action.run.diagnostics';
},
complete: function(args) {
var exitcode = _l('message.diagnostics.exitcode');
exitcode = exitcode.replace('var', args.exitcode);
var stderr = _l('message.diagnostics.stderr');
stderr = stderr.replace('var', args.stderr);
var stdout = _l('message.diagnostics.stdout');
stdout = stdout.replace('var', args.stdout);
var msg = "<div style='text-align: left; overflow-y: auto'>" + exitcode + "<br><br>" + stderr + "<br><br>" + stdout + "</div>";
return msg;
}
},
createForm: {
title: 'label.action.run.diagnostics',
desc: '',
fields: {
type: {
label: 'label.run.diagnostics.type',
validation: {
required: true
},
select: function (args) {
var items = [];
items.push({
id: "ping",
description: "Ping"
});
items.push({
id: "traceroute",
description: "Traceroute"
});
items.push({
id: "arping",
description: "Arping"
});
args.response.success({
data: items
});
}
},
destination: {
label: 'label.run.diagnostics.destination',
validation: {
required: true
}
},
extra: {
label: 'label.run.diagnostics.extra'
}
}
},
action: function (args) {
$.ajax({
url: createURL("runDiagnostics&targetid=" + args.context.systemVMs[0].id + "&ipaddress=" + args.data.destination + "&type=" + args.data.type + "&params=" + args.data.extra),
dataType: "json",
async: true,
success: function(json) {
var jid = json.rundiagnosticsresponse.jobid;
args.response.success({
_custom: {
jobId : jid,
getUpdatedItem: function (json) {
return json.queryasyncjobresultresponse.jobresult.diagnostics;
},
getActionFilter: function(){
return systemvmActionfilter;
}
}
});
}
}); //end ajax
},
notification: {
poll: pollAsyncJobResult
}
},
scaleUp: {
label: 'label.change.service.offering',
createForm: {
@ -10183,6 +10353,92 @@
}
},
// VR Diagnostics
diagnostics: {
label: 'label.action.run.diagnostics',
messages: {
notification: function (args) {
return 'label.action.run.diagnostics';
},
complete: function(args) {
var exitcode = _l('message.diagnostics.exitcode');
exitcode = exitcode.replace('var', args.exitcode);
var stderr = _l('message.diagnostics.stderr');
stderr = stderr.replace('var', args.stderr);
var stdout = _l('message.diagnostics.stdout');
stdout = stdout.replace('var', args.stdout);
var msg = "<div style='text-align: left; overflow-y: auto'>" + exitcode + "<br><br>" + stderr + "<br><br>" + stdout + "</div>";
return msg;
}
},
createForm: {
title: 'label.action.run.diagnostics',
desc: '',
fields: {
type: {
label: 'label.run.diagnostics.type',
validation: {
required: true
},
select: function (args) {
var items = [];
items.push({
id: "ping",
description: "Ping"
});
items.push({
id: "traceroute",
description: "Traceroute"
});
items.push({
id: "arping",
description: "Arping"
});
args.response.success({
data: items
});
}
},
destination: {
label: 'label.run.diagnostics.destination',
validation: {
required: true
}
},
extra: {
label: 'label.run.diagnostics.extra'
}
}
},
action: function (args) {
$.ajax({
url: createURL("runDiagnostics&targetid=" + args.context.routers[0].id + "&ipaddress=" + args.data.destination + "&type=" + args.data.type + "&params=" + args.data.extra),
dataType: "json",
async: true,
success: function(json) {
var jid = json.rundiagnosticsresponse.jobid;
args.response.success({
_custom: {
jobId : jid,
getUpdatedItem: function (json) {
return json.queryasyncjobresultresponse.jobresult.diagnostics;
},
getActionFilter: function(){
return routerActionfilter;
}
}
});
}
}); //end ajax
},
notification: {
poll: pollAsyncJobResult
}
},
scaleUp: { //*** Infrastructure > Virtual Routers > change service offering ***
label: 'label.change.service.offering',
createForm: {
@ -11448,6 +11704,91 @@
}
},
diagnostics: {
label: 'label.action.run.diagnostics',
messages: {
notification: function (args) {
return 'label.action.run.diagnostics';
},
complete: function(args) {
var exitcode = _l('message.diagnostics.exitcode');
exitcode = exitcode.replace('var', args.exitcode);
var stderr = _l('message.diagnostics.stderr');
stderr = stderr.replace('var', args.stderr);
var stdout = _l('message.diagnostics.stdout');
stdout = stdout.replace('var', args.stdout);
var msg = "<div style='text-align: left; overflow-y: auto'>" + exitcode + "<br><br>" + stderr + "<br><br>" + stdout + "</div>";
return msg;
}
},
createForm: {
title: 'label.action.run.diagnostics',
desc: '',
fields: {
type: {
label: 'label.run.diagnostics.type',
validation: {
required: true
},
select: function (args) {
var items = [];
items.push({
id: "ping",
description: "Ping"
});
items.push({
id: "traceroute",
description: "Traceroute"
});
items.push({
id: "arping",
description: "Arping"
});
args.response.success({
data: items
});
}
},
destination: {
label: 'label.run.diagnostics.destination',
validation: {
required: true
}
},
extra: {
label: 'label.run.diagnostics.extra'
}
}
},
action: function (args) {
$.ajax({
url: createURL("runDiagnostics&targetid=" + args.context.systemVMs[0].id + "&ipaddress=" + args.data.destination + "&type=" + args.data.type + "&params=" + args.data.extra),
dataType: "json",
async: true,
success: function(json) {
var jid = json.rundiagnosticsresponse.jobid;
args.response.success({
_custom: {
jobId : jid,
getUpdatedItem: function (json) {
return json.queryasyncjobresultresponse.jobresult.diagnostics;
},
getActionFilter: function(){
return systemvmActionfilter;
}
}
});
}
}); //end ajax
},
notification: {
poll: pollAsyncJobResult
}
},
scaleUp: { //*** Infrastructure > System VMs (consoleProxy or SSVM) > change service offering ***
label: 'label.change.service.offering',
createForm: {
@ -11541,8 +11882,6 @@
}
},
viewConsole: {
label: 'label.view.console',
action: {
@ -22094,8 +22433,10 @@
allowedActions.push("remove");
allowedActions.push("viewConsole");
if (isAdmin())
allowedActions.push("migrate");
if (isAdmin()) {
allowedActions.push("migrate");
allowedActions.push("diagnostics");
}
} else if (jsonObj.state == 'Starting') {
if (isAdmin()) {
allowedActions.push("viewConsole");
@ -22145,8 +22486,10 @@
}
allowedActions.push("viewConsole");
if (isAdmin())
allowedActions.push("migrate");
if (isAdmin()) {
allowedActions.push("migrate");
allowedActions.push("diagnostics");
}
} else if (jsonObj.state == 'Starting') {
if (isAdmin()) {
allowedActions.push("viewConsole");