diff options
Diffstat (limited to 'adapters/mso-adapter-utils')
5 files changed, 54 insertions, 18 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java index 698b605be3..740eb778b0 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java @@ -20,6 +20,8 @@ package org.onap.so.openstack.utils; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import org.onap.so.cloud.authentication.KeystoneAuthHolder; import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; @@ -30,7 +32,6 @@ import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.glance.Glance; import com.woorea.openstack.glance.model.Images; - @Component public class GlanceClientImpl extends MsoCommonUtils { @@ -70,10 +71,18 @@ public class GlanceClientImpl extends MsoCommonUtils { public Images queryImages(String cloudSiteId, String tenantId, int limit, String visibility, String marker, String name) throws MsoCloudSiteNotFound, GlanceClientException { try { + String encodedName = null; + if (name != null) { + try { + encodedName = URLEncoder.encode(name, "UTF-8"); + } catch (UnsupportedEncodingException e) { + logger.error("error encoding query parameter: {}", encodedName); + } + } Glance glanceClient = getGlanceClient(cloudSiteId, tenantId); // list is set to false, otherwise an invalid URL is appended OpenStackRequest<Images> request = glanceClient.images().list(false).queryParam("visibility", visibility) - .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name); + .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", encodedName); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Glance Client", e); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index 62d9f068f9..c33160d255 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -184,6 +184,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { if (CREATE_COMPLETE.equals(currentStack.getStackStatus())) { new StackInfoMapper(currentStack).map(); } else if (CREATE_IN_PROGRESS.equals(currentStack.getStackStatus())) { + // TODO should check poll for completion right here currentStack = processCreateStack(cloudSiteId, tenantId, timeoutMinutes, backout, currentStack, createStack, true); } else if (CREATE_FAILED.equals(currentStack.getStackStatus()) @@ -322,6 +323,27 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { } } + public Stack postProcessStackUpdate(Stack updateStack) throws MsoOpenstackException { + if (!"UPDATE_COMPLETE".equals(updateStack.getStackStatus())) { + logger.error("{} Stack status: {} Stack status reason: {} {} Update Stack error", + MessageEnum.RA_UPDATE_STACK_ERR, updateStack.getStackStatus(), updateStack.getStackStatusReason(), + ErrorCode.DataError.getValue()); + + MsoOpenstackException me = null; + if ("UPDATE_IN_PROGRESS".equals(updateStack.getStackStatus())) { + me = new MsoOpenstackException(0, "", "Stack Update Timeout"); + } else { + String error = + "Stack error (" + updateStack.getStackStatus() + "): " + updateStack.getStackStatusReason(); + me = new MsoOpenstackException(0, "", error); + } + me.addContext("UpdateStack"); + throw me; + } else { + return updateStack; + } + } + public Stack pollStackForStatus(int timeoutMinutes, Stack stack, String stackStatus, String cloudSiteId, String tenantId, boolean notFoundIsSuccess) throws MsoException { int pollingFrequency = diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java index 3e28e5c45a..9a9bccfb5d 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java @@ -24,7 +24,6 @@ package org.onap.so.openstack.utils; import java.util.ArrayList; -import java.util.Calendar; import java.util.List; import java.util.Optional; import org.onap.so.cloud.CloudConfig; diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java index 8f9dbd1f5a..96ed408c80 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java @@ -20,6 +20,8 @@ package org.onap.so.openstack.utils; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import org.onap.so.cloud.authentication.KeystoneAuthHolder; import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; @@ -73,9 +75,17 @@ public class NeutronClientImpl extends MsoCommonUtils { public Networks queryNetworks(String cloudSiteId, String tenantId, int limit, String marker, String name, String id) throws MsoCloudSiteNotFound, NeutronClientException { try { + String encodedName = null; + if (name != null) { + try { + encodedName = URLEncoder.encode(name, "UTF-8"); + } catch (UnsupportedEncodingException e) { + logger.error("error encoding query parameter: {}", encodedName); + } + } Quantum neutronClient = getNeutronClient(cloudSiteId, tenantId); OpenStackRequest<Networks> request = neutronClient.networks().list().queryParam("id", id) - .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name); + .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", encodedName); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { logger.error("Error building Neutron Client", e); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java index 4dc139f37d..5d28eaaf71 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java @@ -20,6 +20,7 @@ package org.onap.so.openstack.utils; +import java.io.IOException; import org.onap.so.cloud.authentication.KeystoneAuthHolder; import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; @@ -224,20 +225,15 @@ public class NovaClientImpl extends MsoCommonUtils { } public void postActionToServer(String cloudSiteId, String tenantId, String id, String request) - throws NovaClientException { - try { - ObjectMapper mapper = new ObjectMapper(); - JsonNode actualObj = mapper.readTree(request); - Entity<JsonNode> openstackEntity = new Entity<>(actualObj, "application/json"); - CharSequence actionPath = "/servers/" + id + "/action"; - Nova novaClient = getNovaClient(cloudSiteId, tenantId); - OpenStackRequest<Void> OSRequest = - new OpenStackRequest<>(novaClient, HttpMethod.POST, actionPath, openstackEntity, Void.class); - executeAndRecordOpenstackRequest(OSRequest, false); - } catch (Exception e) { - logger.error("Error building Nova Client", e); - throw new NovaClientException("Error building Nova Client", e); - } + throws IOException, MsoException { + ObjectMapper mapper = new ObjectMapper(); + JsonNode actualObj = mapper.readTree(request); + Entity<JsonNode> openstackEntity = new Entity<>(actualObj, "application/json"); + CharSequence actionPath = "/servers/" + id + "/action"; + Nova novaClient = getNovaClient(cloudSiteId, tenantId); + OpenStackRequest<Void> OSRequest = + new OpenStackRequest<>(novaClient, HttpMethod.POST, actionPath, openstackEntity, Void.class); + executeAndRecordOpenstackRequest(OSRequest, false); } public void attachVolume(String cloudSiteId, String tenantId, String serverId, VolumeAttachment volumeAttachment) |