
org.xlcloud.openstack.client.OpenStackCeilometerClient Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2012 AMG.lab, a Bull Group Company
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.xlcloud.openstack.client;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.xlcloud.config.ConfigParam;
import org.xlcloud.openstack.api.MeteringApi;
import org.xlcloud.openstack.model.ceilometer.Sample;
import org.xlcloud.openstack.rest.OpenStackRestClient;
import org.xlcloud.openstack.rest.RestClientType;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
//import org.xlcloud.openstack.model.ceilometer.Meter;
//import org.xlcloud.openstack.model.ceilometer.Resource;
/**
*
* @author Andrzej Stasiak, AMG.net
*
*/
public class OpenStackCeilometerClient extends WebResourceRequestBuilderDecorator implements MeteringApi {
private static final Logger LOG = Logger.getLogger(OpenStackCeilometerClient.class);
private static final String METERS = "meters";
@Inject
@OpenStackRestClient(RestClientType.HEAT)
private Client resourceClient;
@Inject
@ConfigParam
private String ceilometerUrl;
private WebResource resource;
@PostConstruct
public void init() {
LOG.debug("Using Jersey client " + resourceClient.hashCode());
resource = resourceClient.resource(ceilometerUrl);
}
// @Override
// public List listSamples(String meterId) {
// ClientResponse clientResponse = get(ClientResponse.class,resource.path(METERS+"/"+meterId));
// return clientResponse.getEntity(new GenericType>() {});
// }
//
// @Override
// public List listResources() {
// ClientResponse clientResponse = get(ClientResponse.class,resource.path(RESOURCES));
// return clientResponse.getEntity(new GenericType>() {});
// }
//
// @Override
// public List listMeters() {
// ClientResponse clientResponse = get(ClientResponse.class,resource.path(METERS));
// return clientResponse.getEntity(new GenericType>() {});
// }
//
@Override
public List createSamples(String meterId, List samples) {
fillCounterNames(meterId, samples);
ClientResponse clientResponse = post(ClientResponse.class,samples,resource.path(METERS+"/"+meterId));
return clientResponse.getEntity(new GenericType>() {});
}
private void fillCounterNames(String meterId, List samples) {
for(Sample sample : samples) {
sample.setCounter_name(meterId);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy