Package org.onosproject.cli
Class AbstractShellCommand
- java.lang.Object
-
- org.onosproject.cli.AbstractShellCommand
-
- All Implemented Interfaces:
org.apache.karaf.shell.api.action.Action
,org.onosproject.codec.CodecContext
- Direct Known Subclasses:
AddProtectedTransportIntentCommand
,AddTestFlowsCommand
,AllocationsCommand
,AnnotateDeviceCommand
,AnnotateHostCommand
,AnnotateLinkCommand
,AnnotatePortCommand
,ApplicationCommand
,ApplicationIdListCommand
,ApplicationsListCommand
,BalanceMastersCommand
,ComponentConfigCommand
,ConfigureLinkCommand
,ConnectivityIntentCommand
,CounterCommand
,CountersListCommand
,DeviceControllersCommand
,DeviceDriversCommand
,DeviceInterfaceAddCommand
,DeviceInterfaceRemoveCommand
,DeviceKeyAddCommand
,DeviceKeyListCommand
,DeviceKeyRemoveCommand
,DevicePortsRemoveCommand
,DevicePortStateCommand
,DevicePortStatsCommand
,DeviceRebootCommand
,DeviceRemoveCommand
,DeviceRoleCommand
,DeviceSetControllersCommand
,DevicesListCommand
,DeviceTimeCommand
,DriverProvidersListCommand
,DriversListCommand
,EdgePortsListCommand
,FlowObjectiveCompositionCommand
,FlowObjectiveNextListCommand
,FlowObjectivePendingNextCommand
,FlowObjectiveQueueClearCommand
,FlowObjectiveQueueListCommand
,FlowsListCommand
,GetDomainsCommand
,GetFlowStatisticsCommand
,GetStatisticsCommand
,GroupsListCommand
,HostRemoveCommand
,HostsListCommand
,IntentCycleCommand
,IntentDetailsCommand
,IntentListCompilers
,IntentListInstallers
,IntentPurgeCommand
,IntentPushTestCommand
,IntentRemoveCommand
,IntentsDiagnosisCommand
,IntentsListCommand
,InterfaceAddCommand
,InterfaceRemoveCommand
,InterfacesListCommand
,IssuCommand
,LayoutAddCommand
,LayoutListCommand
,LeaderCommand
,LinksListCommand
,MapsListCommand
,MarkCommand
,MastersListCommand
,McastDeleteCommand
,McastJoinCommand
,McastRoutesListCommand
,McastShowCommand
,MembershipsListCommand
,MeterAddCommand
,MeterRemoveCommand
,MetersListCommand
,MetricsListCommand
,NeighbourHandlersListCommand
,NetworkConfigCommand
,NetworkConfigRegistryCommand
,NodesListCommand
,PacketProcessorsListCommand
,PacketRequestsListCommand
,PartitionsListCommand
,PipeconfCommand
,PortQueryVlansCommand
,PowerConfigCommand
,PrettyJson
,PrettyXml
,QueuesListCommand
,RandomIntentCommand
,RegionAddCommand
,RegionAddDevicesCommand
,RegionAddPeerLocCommand
,RegionListCommand
,RegionRemoveCommand
,RegionRemoveDevicesCommand
,RegionUpdateCommand
,ResourcesCommand
,ReviewCommand
,RolesCommand
,ScrListCommand
,StorageNodesListCommand
,SummaryCommand
,TableStatisticsCommand
,TestAllocateResource
,TestProtectionEndpointIntentCommand
,TopologyCommand
,TransactionsCommand
,WipeOutCommand
public abstract class AbstractShellCommand extends java.lang.Object implements org.apache.karaf.shell.api.action.Action, org.onosproject.codec.CodecContext
Base abstraction of Karaf shell commands.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
log
-
Constructor Summary
Constructors Constructor Description AbstractShellCommand()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.databind.node.ObjectNode
annotations(com.fasterxml.jackson.databind.ObjectMapper mapper, org.onosproject.net.Annotations annotations)
Produces a JSON object from the specified key/value annotations.static java.lang.String
annotations(org.onosproject.net.Annotations annotations)
Produces a string image of the specified key/value annotations.static java.lang.String
annotations(org.onosproject.net.Annotations annotations, java.util.Set<java.lang.String> excludedKeys)
Produces a string image of the specified key/value annotations.protected org.onosproject.core.ApplicationId
appId()
Returns application ID for the CLI.<T> org.onosproject.codec.JsonCodec<T>
codec(java.lang.Class<T> entityClass)
protected abstract void
doExecute()
Body of the shell command.void
error(java.lang.String format, java.lang.Object... args)
Prints the arguments using the specified format to error stream.java.lang.Object
execute()
static <T> T
get(java.lang.Class<T> serviceClass)
Returns the reference to the implementation of the specified service.<T> T
getService(java.lang.Class<T> serviceClass)
<T> com.fasterxml.jackson.databind.node.ObjectNode
jsonForEntity(T entity, java.lang.Class<T> entityClass)
Generates a Json representation of an object.com.fasterxml.jackson.databind.ObjectMapper
mapper()
protected boolean
outputJson()
Indicates whether JSON format should be output.void
print(java.lang.String format, java.lang.Object... args)
Prints the arguments using the specified format.
-
-
-
Method Detail
-
get
public static <T> T get(java.lang.Class<T> serviceClass)
Returns the reference to the implementation of the specified service.- Type Parameters:
T
- type of service- Parameters:
serviceClass
- service class- Returns:
- service implementation
- Throws:
org.onlab.osgi.ServiceNotFoundException
- if service is unavailable
-
appId
protected org.onosproject.core.ApplicationId appId()
Returns application ID for the CLI.- Returns:
- command-line application identifier
-
print
public void print(java.lang.String format, java.lang.Object... args)
Prints the arguments using the specified format.- Parameters:
format
- format string; seeString.format(java.lang.String, java.lang.Object...)
args
- arguments
-
error
public void error(java.lang.String format, java.lang.Object... args)
Prints the arguments using the specified format to error stream.- Parameters:
format
- format string; seeString.format(java.lang.String, java.lang.Object...)
args
- arguments
-
annotations
public static java.lang.String annotations(org.onosproject.net.Annotations annotations)
Produces a string image of the specified key/value annotations.- Parameters:
annotations
- key/value annotations- Returns:
- string image with ", k1=v1, k2=v2, ..." pairs
-
annotations
public static java.lang.String annotations(org.onosproject.net.Annotations annotations, java.util.Set<java.lang.String> excludedKeys)
Produces a string image of the specified key/value annotations. Excludes the keys in the given Set.- Parameters:
annotations
- key/value annotationsexcludedKeys
- keys not to add in the resulting string- Returns:
- string image with ", k1=v1, k2=v2, ..." pairs
-
annotations
public static com.fasterxml.jackson.databind.node.ObjectNode annotations(com.fasterxml.jackson.databind.ObjectMapper mapper, org.onosproject.net.Annotations annotations)
Produces a JSON object from the specified key/value annotations.- Parameters:
mapper
- ObjectMapper to use while converting to JSONannotations
- key/value annotations- Returns:
- JSON object
-
outputJson
protected boolean outputJson()
Indicates whether JSON format should be output.- Returns:
- true if JSON is requested
-
execute
public final java.lang.Object execute() throws java.lang.Exception
- Specified by:
execute
in interfaceorg.apache.karaf.shell.api.action.Action
- Throws:
java.lang.Exception
-
doExecute
protected abstract void doExecute() throws java.lang.Exception
Body of the shell command.- Throws:
java.lang.Exception
- thrown when problem is encountered
-
mapper
public com.fasterxml.jackson.databind.ObjectMapper mapper()
- Specified by:
mapper
in interfaceorg.onosproject.codec.CodecContext
-
codec
public <T> org.onosproject.codec.JsonCodec<T> codec(java.lang.Class<T> entityClass)
- Specified by:
codec
in interfaceorg.onosproject.codec.CodecContext
-
getService
public <T> T getService(java.lang.Class<T> serviceClass)
- Specified by:
getService
in interfaceorg.onosproject.codec.CodecContext
-
jsonForEntity
public <T> com.fasterxml.jackson.databind.node.ObjectNode jsonForEntity(T entity, java.lang.Class<T> entityClass)
Generates a Json representation of an object.- Type Parameters:
T
- Type of the object being formatted- Parameters:
entity
- object to generate JSON forentityClass
- class to format with - this chooses which codec to use- Returns:
- JSON object representation
-
-