use of org.onosproject.net.host.HostProviderRegistry in project onos by opennetworkinglab.
the class HostsWebResource method createAndAddHost.
/**
* Creates a new host based on JSON input and adds it to the current
* host inventory.
*
* @param stream input JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel HostPut
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createAndAddHost(InputStream stream) {
URI location;
HostProviderRegistry hostProviderRegistry = get(HostProviderRegistry.class);
InternalHostProvider hostProvider = new InternalHostProvider();
try {
// Parse the input stream
ObjectNode root = readTreeFromStream(mapper(), stream);
HostProviderService hostProviderService = hostProviderRegistry.register(hostProvider);
hostProvider.setHostProviderService(hostProviderService);
HostId hostId = hostProvider.parseHost(root);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("hosts").path(hostId.mac().toString()).path(hostId.vlanId().toString());
location = locationBuilder.build();
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
} finally {
hostProviderRegistry.unregister(hostProvider);
}
return Response.created(location).build();
}
Aggregations