package org.opennaas.extensions.powernet.capability.mgt.shell; import org.apache.felix.gogo.commands.Argument; import org.apache.felix.gogo.commands.Command; import org.opennaas.core.resources.IResource; import org.opennaas.core.resources.shell.GenericKarafCommand; import org.opennaas.extensions.powernet.capability.mgt.IPowerNetManagementCapability; /** * * @author Elisabeth Rigol * */ @Command(scope = "example", name = "sayHello", description = "It will say hello.") public class ExampleCommand extends GenericKarafCommand { @Argument(index = 0, name = "resourceType:resourceName", description = "The resource id", required = true, multiValued = false) private String resourceName; @Argument(index = 1, name = "userName", description = "The name of the person we will greet.", required = true, multiValued = false) private String username; @Override protected Object doExecute() throws Exception { printInitCommand("sayHello"); try { IResource resource = getResourceFromFriendlyName(resourceName); IPowerNetManagementCapability capab = (IPowerNetManagementCapability) resource .getCapabilityByInterface(IPowerNetManagementCapability.class); String greeting = capab.createPowerConsumer(username); printInfo(resourceName + " says : " + greeting); } catch (Exception e) { printError("Error greeting from resource " + resourceName); printError(e); } finally { printEndCommand(); } printEndCommand(); return null; } }