public class HTTPClient extends Client
Constructor and Description |
---|
HTTPClient(URI endpoint)
Constructor.
|
HTTPClient(URI endpoint,
Authentication authentication)
Constructor.
|
HTTPClient(URI endpoint,
Authentication authentication,
String mediaType,
boolean autoconnect)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
connect()
Establishes a connection.
|
URI |
create(cz.cesnet.cloud.occi.core.Entity entity)
Creates a new resource on the server.
|
boolean |
delete(String resourceType)
Deletes all resource of a certain resource type from the server.
|
boolean |
delete(URI resourceIdentifier)
Deletes all resource of a certain resource type or specific resource from
the server.
|
List<cz.cesnet.cloud.occi.core.Entity> |
describe()
Retrieves descriptions for all available resources.
|
List<cz.cesnet.cloud.occi.core.Entity> |
describe(String resourceType)
Retrieves descriptions for available resources of a certain type.
|
List<cz.cesnet.cloud.occi.core.Entity> |
describe(URI resourceIdentifier)
Retrieves descriptions for available resources specified by a type
identifier or resource identifier.
|
String |
getMediaType()
Returns media type of the connection.
|
List<URI> |
list()
Retrieves all available resources represented by resource locations
(URIs).
|
List<URI> |
list(String resourceType)
Retrieves available resources of a certain type represented by resource
locations (URIs).
|
List<URI> |
list(URI resourceIdentifier)
Retrieves available resources of a certain type represented by resource
locations (URIs).
|
void |
refresh()
Refreshes the Model used inside the client.
|
void |
setMediaType(String mediaType)
Sets media type for the connection.
|
boolean |
trigger(String resourceType,
cz.cesnet.cloud.occi.core.ActionInstance action)
Triggers given action on a specified set of resources.
|
boolean |
trigger(URI resourceIdentifier,
cz.cesnet.cloud.occi.core.ActionInstance action)
Triggers given action on a set of resources or on a specified resource.
|
URI |
update(cz.cesnet.cloud.occi.core.Entity entity) |
getAuthentication, getEndpoint, getModel, isConnected, setAuthentication, setConnected, setEndpoint, setModel
public HTTPClient(URI endpoint, Authentication authentication, String mediaType, boolean autoconnect) throws CommunicationException
HTTPClient has three constructors via which one can set remote server's endpoint, authentication method, media type for HTTP messages and whether client should automatically connect to the server or not.
By default text/plain is used as media type and client is initialized without authentication method. Client automatically connects to the remote server by default when authentication method is set.
Examples:
Client client = new HTTPClient(URI.create("https://remote.server.net")); client.connect();
Client client = new HTTPClient(URI.create("https://remote.server.net"), new BasicAuthentication("username", "password"), MediaType.TEXT_OCCI, true);
endpoint
- cannot be nullauthentication
- authentication method which will be used to
authenticate client against the servermediaType
- string representing HTTP media type used in
communicationautoconnect
- CommunicationException
public HTTPClient(URI endpoint, Authentication authentication) throws CommunicationException
endpoint
- cannot be nullauthentication
- CommunicationException
public HTTPClient(URI endpoint) throws CommunicationException
endpoint
- cannot be nullCommunicationException
public void setMediaType(String mediaType)
mediaType
- media typepublic String getMediaType()
public void connect() throws CommunicationException
Client
connect
in class Client
CommunicationException
- when error occured during the
communication with serverClient.connect()
public List<URI> list() throws CommunicationException
Client
Retrieves all available resources represented by resource locations (URIs).
Example:
List<URI> list = client.list();
list
in class Client
CommunicationException
- when error occured during the
communication with serverClient.list()
public List<URI> list(String resourceType) throws CommunicationException
Client
Example:
List<URI> list = client.list("compute");
list
in class Client
resourceType
- resource type in shortened format (e.g. "compute",
"storage", "network")CommunicationException
- when error occured during the
communication with serverClient.list(java.lang.String)
public List<URI> list(URI resourceIdentifier) throws CommunicationException
Client
Example:
List<URI> list = client.list(URI.create("http://schemas.ogf.org/occi/infrastructure#network"));
list
in class Client
resourceIdentifier
- full resource type identifierCommunicationException
- when error occured during the
communication with serverClient.list(java.net.URI)
public List<cz.cesnet.cloud.occi.core.Entity> describe() throws CommunicationException
Client
Example:
List<Entity> list = client.describe();
describe
in class Client
CommunicationException
- when error occured during the
communication with serverClient.describe()
public List<cz.cesnet.cloud.occi.core.Entity> describe(String resourceType) throws CommunicationException
Client
Example:
List<Entity> list = client.describe("compute");
describe
in class Client
resourceType
- resource type in shortened format (e.g. "compute",
"storage", "network")CommunicationException
- when error occured during the
communication with serverClient.describe(java.lang.String)
public List<cz.cesnet.cloud.occi.core.Entity> describe(URI resourceIdentifier) throws CommunicationException
Client
Example:
List<Entity> list = client.describe(URI.create("http://schemas.ogf.org/occi/infrastructure#network"));
...
list = client.describe(URI.create("https://remote.server.net/storage/123"));
describe
in class Client
resourceIdentifier
- either full resource type identifier or full
resource identifierCommunicationException
- when error occured during the
communication with serverClient.describe(java.net.URI)
public URI create(cz.cesnet.cloud.occi.core.Entity entity) throws CommunicationException
Client
Example:
Model model = client.getModel();
EntityBuilder entityBuilder = new EntityBuilder(model);
Compute compute = entityBuilder.getCompute();
compute.addMixin(model.findMixin("debian7", "os_tpl"));
compute.addMixin(model.findMixin("small", "resource_tpl"));
compute.setMemory(1024);
compute.setCores(4);
URI location = client.create(compute);
create
in class Client
entity
- Creates a new resource on the server.CommunicationException
- when error occured during the
communication with serverClient.create(cz.cesnet.cloud.occi.core.Entity)
public URI update(cz.cesnet.cloud.occi.core.Entity entity) throws CommunicationException
update
in class Client
CommunicationException
Client.update(cz.cesnet.cloud.occi.core.Entity)
public boolean delete(String resourceType) throws CommunicationException
Client
Example:
boolean wasSuccessful = client.delete("compute");
delete
in class Client
resourceType
- resource type in shortened format (e.g. "compute",
"storage", "network")CommunicationException
- when error occured during the
communication with serverClient.delete(java.lang.String)
public boolean delete(URI resourceIdentifier) throws CommunicationException
Client
Example:
boolean wasSuccessful = client.delete(URI.create("http://schemas.ogf.org/occi/infrastructure#network"));
...
wasSuccessful = client.delete(URI.create("https://remote.server.net/storage/123"));
delete
in class Client
resourceIdentifier
- either full resource type identifier or full
resource identifierCommunicationException
- when error occured during the
communication with serverClient.delete(java.net.URI)
public boolean trigger(String resourceType, cz.cesnet.cloud.occi.core.ActionInstance action) throws CommunicationException
Client
Example:
Model model = client.getModel();
EntityBuilder entityBuilder = new EntityBuilder(model);
ActionInstance actionInstance = entityBuilder.getActionInstance("start");
boolean wasSuccessful = client.trigger("compute", actionInstance);
trigger
in class Client
resourceType
- resource type in shortened format (e.g. "compute",
"storage", "network")action
- type of actionCommunicationException
- when error occured during the
communication with serverClient.trigger(java.lang.String,
cz.cesnet.cloud.occi.core.ActionInstance)
public boolean trigger(URI resourceIdentifier, cz.cesnet.cloud.occi.core.ActionInstance action) throws CommunicationException
Client
Example:
Model model = client.getModel();
EntityBuilder entityBuilder = new EntityBuilder(model);
ActionInstance actionInstance = entityBuilder.getActionInstance("start");
boolean wasSuccessful = client.trigger(URI.create("http://schemas.ogf.org/occi/infrastructure#network"), actionInstance);
...
wasSuccessful = client.trigger(URI.create("https://remote.server.net/compute/456"), actionInstance);
trigger
in class Client
resourceIdentifier
- either full resource type identifier or full
resource identifieraction
- type of actionCommunicationException
- when error occured during the
communication with serverClient.trigger(java.net.URI,
cz.cesnet.cloud.occi.core.ActionInstance)
public void refresh() throws CommunicationException
Client
refresh
in class Client
CommunicationException
- when error occured during the
communication with serverClient.refresh()
Copyright © 2016. All Rights Reserved.