aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/ro/ResourceServiceConsumer.java
blob: 65431a2b3d974db1a8448fc12a27ca7d99b50348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * Copyright 2016 [ZTE] and others.
 *
 * 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.openo.commontosca.catalog.model.externalservice.ro;

import org.openo.commontosca.catalog.common.MSBUtil;
import org.openo.commontosca.catalog.common.ToolUtil;
import org.openo.commontosca.catalog.model.externalservice.entity.roEntity.ResourceResponseEntity;
import org.openo.commontosca.catalog.model.externalservice.entity.roEntity.VimEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
import com.google.gson.Gson;

/**
 * The roc resource service.
 * @author 10189609
 *
 */
public class ResourceServiceConsumer {
	private static final Logger LOG = LoggerFactory.getLogger(ResourceServiceConsumer.class);
	
	private static final String RESOURCE_REST_RESULT = "SUCCESS";
	
	/**
	 * get vim entity from roc by vimid
	 * @param vimId id
	 * @return vim entity
	 */
	public static VimEntity getResourceVim(String vimId) {
		LOG.info("begin query vim info from roc,vimId:" + vimId);
		IResourceServiceRest resourceserviceproxy = ConsumerFactory
				.createConsumer(MSBUtil.getRocBaseUrl(), IResourceServiceRest.class);	
		String result = "";
		try {
			result = resourceserviceproxy.getResourceVim(vimId);
		} catch (Exception e) {
			LOG.error("query vim info faild.", e);
			return null;
		}
		if (ToolUtil.isEmptyString(result)) {
			LOG.error("query vim info faild, vim info is null, vimId:" + vimId);
			return null;
		}
		
		Gson gson = new Gson();
		ResourceResponseEntity responseEntity = gson.fromJson(result, ResourceResponseEntity.class);
		if (!RESOURCE_REST_RESULT.equalsIgnoreCase(responseEntity.getOperationResult())) 
		{
			LOG.error("query vim info faild.vimId:" + vimId);
			return null;
		}
		if (responseEntity.getData().size() <= 0)
        {
			LOG.error("query vim info faild, vim info is empty, vimId:" + vimId);
            return null;
        }
		
		LOG.info("end query vim info from roc.");
		return responseEntity.getData().get(0);
	}
}