* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
* 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
import java.io.IOException;
import java.net.URISyntaxException;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
public class ChefApiClientImpl implements ChefApiClient {
private final HttpClient httpClient;
- private final ChefApiHeaderFactory chefApiHeaderFactory;
- private String endpoint;
- private String userId;
- private String pemPath;
- private String organizations;
-
- public ChefApiClientImpl(HttpClient httpClient, ChefApiHeaderFactory chefApiHeaderFactory,
- String endpoint, String organizations, String userId, String pemPath) {
+ private final String endpoint;
+ private final String organization;
+ private final HttpHeaderFactory httpHeaderFactory;
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefApiClientImpl.class);
+ public ChefApiClientImpl(HttpClient httpClient, String endpoint, String organization,
+ HttpHeaderFactory httpHeaderFactory) {
this.httpClient = httpClient;
- this.chefApiHeaderFactory = chefApiHeaderFactory;
this.endpoint = endpoint;
- this.organizations = organizations;
- this.userId = userId;
- this.pemPath = pemPath;
+ this.organization = organization;
+ this.httpHeaderFactory = httpHeaderFactory;
}
@Override
public ChefResponse get(String path) {
OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint)
.httpGet()
- .withPath(path)
- .withHeaders(chefApiHeaderFactory.create("GET", path, "", userId, organizations, pemPath));
+ .withPath(getPath(path))
+ .withHeaders(httpHeaderFactory.create("GET", path, ""));
return execute(requestBuilder);
}
public ChefResponse delete(String path) {
OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint)
.httpDelete()
- .withPath(path)
- .withHeaders(chefApiHeaderFactory.create("DELETE", path, "", userId, organizations, pemPath));
+ .withPath(getPath(path))
+ .withHeaders(httpHeaderFactory.create("DELETE", path, ""));
return execute(requestBuilder);
}
public ChefResponse post(String path, String body) {
OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint)
.httpPost(body)
- .withPath(path)
- .withHeaders(chefApiHeaderFactory.create("POST", path, body, userId, organizations, pemPath));
+ .withPath(getPath(path))
+ .withHeaders(httpHeaderFactory.create("POST", path, body));
return execute(requestBuilder);
}
public ChefResponse put(String path, String body) {
OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint)
.httpPut(body)
- .withPath(path)
- .withHeaders(chefApiHeaderFactory.create("PUT", path, body, userId, organizations, pemPath));
+ .withPath(getPath(path))
+ .withHeaders(httpHeaderFactory.create("PUT", path, body));
+ logger.info("request: PATH: "+path+ " body: "+body);
return execute(requestBuilder);
}
private ChefResponse execute(OngoingRequestBuilder chefRequest) {
try {
+ if (httpClient == null) {
+ return ChefResponse.create(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Could not create http client for chef");
+ }
HttpResponse response = httpClient.execute(chefRequest.build());
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity httpEntity = response.getEntity();
return ChefResponse.create(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
+
+ private String getPath(String path) {
+ return "/organizations/" + organization + path;
+ }
}
+