2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
18 package org.onap.dcae.genprocessor;
22 import com.fasterxml.jackson.core.JsonFactory;
23 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class OnboardingAPIClient {
30 static final Logger LOG = LoggerFactory.getLogger(OnboardingAPIClient.class);
32 public static CompList getComponents(String hostOnboardingAPI) {
33 JsonFactory jf = new JsonFactory();
34 ObjectMapper om = new ObjectMapper();
37 URI uri = new URI(hostOnboardingAPI + "/components");
38 return om.readValue(jf.createParser(uri.toURL()), CompList.class);
39 } catch (Exception e) {
40 String message = "Error while pulling components from onboarding API";
41 LOG.error(message, e);
42 throw new OnboardingAPIClientError(message, e);
46 public static Comp getComponent(URI componentUri) {
47 JsonFactory jf = new JsonFactory();
48 ObjectMapper om = new ObjectMapper();
51 return om.readValue(jf.createParser(componentUri.toURL()), Comp.class);
52 } catch (Exception e) {
53 String message = "Error while pulling component from onboarding API";
54 LOG.error(message, e);
55 throw new OnboardingAPIClientError(message, e);
59 public static class OnboardingAPIClientError extends RuntimeException {
60 public OnboardingAPIClientError(String message, Throwable exception) {
61 super(message, exception);