--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.vnfmadapter;
+
+import com.google.gson.Gson;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.JSON;
+import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.GsonHttpMessageConverter;
+
+/**
+ * Configures message converter
+ */
+@Configuration
+public class MessageConverterConfiguration {
+
+ @Bean
+ public HttpMessageConverters customConverters() {
+ final Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
+ final Gson gson = new JSON().getGson();
+ final GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter(gson);
+ messageConverters.add(gsonHttpMessageConverter);
+ return new HttpMessageConverters(true, messageConverters);
+ }
+}
@Override
protected void configure(final HttpSecurity http) throws Exception {
- http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll()
- .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and()
- .httpBasic();
+ http.csrf().disable().authorizeRequests()
+ .antMatchers("/manage/health", "/manage/info", Constants.BASE_URL + "/lcn/**",
+ Constants.BASE_URL + "/grants/**")
+ .permitAll().antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ","))
+ .and().httpBasic();
}
@Override
try {
final String vnfdLocation = getVnfdLocation(new ByteArrayInputStream(onapPackage));
final String onapVnfdContent = getFileInZip(new ByteArrayInputStream(onapPackage), vnfdLocation).toString();
+ logger.debug("VNFD CONTENTS: " + onapVnfdContent);
final JsonObject root = new Gson().toJsonTree(new Yaml().load(onapVnfdContent)).getAsJsonObject();
final JsonObject topologyTemplates = child(root, "topology_template");
logger.debug("VNFMs in ESR: " + vnfmsInEsr);
for (final EsrVnfm vnfm : vnfmsInEsr.getEsrVnfm()) {
+ final EsrSystemInfoList systemInfolist =
+ aaiServiceProvider.invokeGetVnfmEsrSystemInfoList(vnfm.getVnfmId());
+ vnfm.setEsrSystemInfoList(systemInfolist);
if (vnfmHasMatchingEsrSystemInfoType(vnfm, vnf.getNfType())) {
return vnfm;
}
private boolean vnfmHasMatchingEsrSystemInfoType(final EsrVnfm vnfm, final String type) {
logger.debug("Checking VNFM ID: " + vnfm + ": " + vnfm.getVnfmId());
- final EsrSystemInfoList systemInfolist = aaiServiceProvider.invokeGetVnfmEsrSystemInfoList(vnfm.getVnfmId());
+ final EsrSystemInfoList systemInfolist = vnfm.getEsrSystemInfoList();
if (systemInfolist != null) {
for (final EsrSystemInfo esrSystemInfo : systemInfolist.getEsrSystemInfo()) {
if (esrSystemInfo.getType().equals(type)) {
@Override
public GenericVnfs invokeQueryGenericVnf(final String selfLink) {
return aaiClientProvider.getAaiClient()
- .get(GenericVnfs.class,
- AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNFS).queryParam("selflink", selfLink))
+ .get(GenericVnfs.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNFS)
+ .queryParam("selflink", selfLink.replaceAll("https", "http")))
.orElseGet(() -> {
logger.debug("No vnf found in AAI with selflink: {}", selfLink);
return null;
@Override
public Optional<InlineResponse201> getVnf(final String vnfSelfLink) {
- return httpServiceProvider.get(vnfSelfLink, InlineResponse201.class);
+ return httpServiceProvider.get(vnfSelfLink.replaceAll("https", "http"), InlineResponse201.class);
}
@Override
logger.error(errorMessage, exception);
throw new VnfmRequestFailureException(errorMessage, exception);
}
- if (response.getStatusCode() != HttpStatus.OK) {
+ if (response.getStatusCode() != HttpStatus.CREATED) {
final String errorMessage = "Subscription to VNFM " + vnfmId + " returned status code: "
+ response.getStatusCode() + ", request: " + subscriptionRequest;
logger.error(errorMessage);
* @return the URL of the operation
*/
public String getOperationUrl(final String vnfmId, final String operationId) {
- final String url = UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("/vnf_lcm_op_occs/")
+ final String url = UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("vnf_lcm_op_occs")
.pathSegment(operationId).build().toString();
logger.debug("getOperationUrl:" + url);
*/
public String getSubscriptionsUrl(final String vnfmId) {
final String url =
- UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("/subscriptions").build().toString();
+ UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("subscriptions").build().toString();
logger.debug("getSubscriptionUrl:" + url);
return url;
public String getCreationUrl(final String vnfmId) {
final String url =
- UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("/vnf_instances").build().toString();
+ UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("vnf_instances").build().toString();
logger.debug("getCreationUrl:" + url);
return url;
logger.info("Create response: {}", vnfmResponse);
- genericVnf.setSelflink(vnfmResponse.getLinks().getSelf().getHref());
+ genericVnf.setSelflink(getSelfLink(vnfmResponse, vnfm));
aaiServiceProvider.invokePutGenericVnf(genericVnf);
final String vnfIdInVnfm = vnfmResponse.getId();
return response;
}
+ private String getSelfLink(final InlineResponse201 vnfmResponse, final EsrVnfm vnfm) {
+ if (vnfmResponse.getLinks() != null && vnfmResponse.getLinks().getSelf() != null
+ && vnfmResponse.getLinks().getSelf().getHref() != null) {
+ return vnfmResponse.getLinks().getSelf().getHref().replaceAll("https", "http");
+ }
+ return vnfm.getEsrSystemInfoList().getEsrSystemInfo().iterator().next().getServiceUrl() + "/vnf_instances/"
+ + vnfmResponse.getId();
+ }
+
private OamIpAddressSource extractOamIpAddressSource(final CreateVnfRequest request) {
final Map<String, String> additionalParams = request.getAdditionalParams();
try {