Search in sources :

Example 6 with MsoAdapterException

use of org.onap.so.openstack.exceptions.MsoAdapterException in project so by onap.

the class MsoCommonUtilsTest method testRuntimeExceptionToMsoException.

@Test
public final void testRuntimeExceptionToMsoException() {
    RuntimeException re = new RuntimeException("runtime");
    MsoException me = commonUtils.runtimeExceptionToMsoException(re, "ContextError");
    assertTrue(me instanceof MsoAdapterException);
    assertTrue("ContextError".equals(me.getContext()));
    assertTrue(MsoExceptionCategory.INTERNAL.equals(me.getCategory()));
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 7 with MsoAdapterException

use of org.onap.so.openstack.exceptions.MsoAdapterException in project so by onap.

the class MsoNetworkAdapterImpl method mergeSubnets.

private String mergeSubnets(String heatTemplate, List<Subnet> subnets) throws MsoException {
    String resourceTempl = "  subnet_%subnetId%:\n" + "    type: OS::Neutron::Subnet\n" + "    properties:\n" + "      name: %name%\n" + "      network_id: { get_resource: network }\n" + "      cidr: %cidr%\n";
    /*
         * make these optional + "      ip_version: %ipversion%\n" + "      enable_dhcp: %enabledhcp%\n" +
         * "      gateway_ip: %gatewayip%\n" + "      allocation_pools:\n" + "       - start: %poolstart%\n" +
         * "         end: %poolend%\n";
         *
         */
    String outputTempl = "  subnet_id_%subnetId%:\n" + "    description: Openstack subnet identifier\n" + "    value: {get_resource: subnet_%subnetId%}\n";
    String curR;
    String curO;
    StringBuilder resourcesBuf = new StringBuilder();
    StringBuilder outputsBuf = new StringBuilder();
    for (Subnet subnet : subnets) {
        // build template for each subnet
        curR = resourceTempl;
        if (subnet.getSubnetId() != null) {
            curR = curR.replace("%subnetId%", subnet.getSubnetId());
        } else {
            String error = "Missing Required AAI SubnetId for subnet in HEAT Template";
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
            throw new MsoAdapterException(error);
        }
        if (subnet.getSubnetName() != null) {
            curR = curR.replace("%name%", subnet.getSubnetName());
        } else {
            curR = curR.replace("%name%", subnet.getSubnetId());
        }
        if (subnet.getCidr() != null) {
            curR = curR.replace("%cidr%", subnet.getCidr());
        } else {
            String error = "Missing Required cidr for subnet in HEAT Template";
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
            throw new MsoAdapterException(error);
        }
        if (subnet.getIpVersion() != null) {
            curR = curR + "      ip_version: " + subnet.getIpVersion() + "\n";
        }
        if (subnet.getEnableDHCP() != null) {
            curR = curR + "      enable_dhcp: " + Boolean.toString(subnet.getEnableDHCP()) + "\n";
        }
        if (subnet.getGatewayIp() != null && !subnet.getGatewayIp().isEmpty()) {
            curR = curR + "      gateway_ip: " + subnet.getGatewayIp() + "\n";
        }
        if (subnet.getAllocationPools() != null) {
            StringBuilder tempBuf = new StringBuilder();
            tempBuf.append(curR);
            tempBuf.append("      allocation_pools:\n");
            for (Pool pool : subnet.getAllocationPools()) {
                if (!commonUtils.isNullOrEmpty(pool.getStart()) && !commonUtils.isNullOrEmpty(pool.getEnd())) {
                    tempBuf.append("       - start: ");
                    tempBuf.append(pool.getStart());
                    tempBuf.append("\n         end: ");
                    tempBuf.append(pool.getEnd());
                    tempBuf.append("\n");
                }
            }
            curR = tempBuf.toString();
        }
        resourcesBuf.append(curR);
        curO = outputTempl;
        curO = curO.replace("%subnetId%", subnet.getSubnetId());
        outputsBuf.append(curO);
    }
    // append resources and outputs in heatTemplate
    logger.debug("Tempate initial:{}", heatTemplate);
    int outputsIdx = heatTemplate.indexOf("outputs:");
    heatTemplate = insertStr(heatTemplate, outputsBuf.toString(), outputsIdx + 8);
    int resourcesIdx = heatTemplate.indexOf("resources:");
    heatTemplate = insertStr(heatTemplate, resourcesBuf.toString(), resourcesIdx + 10);
    logger.debug("Template updated with all subnets:{}", heatTemplate);
    return heatTemplate;
}
Also used : MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) Pool(org.onap.so.openstack.beans.Pool) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet)

Example 8 with MsoAdapterException

use of org.onap.so.openstack.exceptions.MsoAdapterException in project so by onap.

the class MsoCommonUtils method getKeystoneAuthHolder.

/**
 * Gets the Keystone Authorization
 *
 * @param cloudSite the cloud site
 * @param tenantId the tenant id
 * @return the Neutron client
 * @throws MsoException the mso exception
 */
protected KeystoneAuthHolder getKeystoneAuthHolder(String cloudSiteId, String tenantId, String serviceName) throws MsoException {
    CloudIdentity cloudIdentity = null;
    try {
        CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
        String cloudId = cloudSite.getId();
        String region = cloudSite.getRegionId();
        cloudIdentity = cloudSite.getIdentityService();
        MsoTenantUtils tenantUtils = tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
        String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity);
        if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType())) {
            Access access = getKeystone(tenantId, cloudIdentity, keystoneUrl);
            try {
                KeystoneAuthHolder keystoneAuthV2 = new KeystoneAuthHolder();
                keystoneAuthV2.setServiceUrl(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), serviceName, region, "public"));
                keystoneAuthV2.setId(access.getToken().getId());
                return keystoneAuthV2;
            } catch (RuntimeException e) {
                String error = "Openstack did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
                throw new MsoAdapterException(error, e);
            }
        } else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
            try {
                return keystoneV3Authentication.getToken(cloudSite, tenantId, serviceName);
            } catch (ServiceEndpointNotFoundException e) {
                String error = "cloud did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
                throw new MsoAdapterException(error, e);
            }
        } else {
            throw new MsoAdapterException("Unknown Keystone Server Type");
        }
    } catch (OpenStackResponseException e) {
        if (e.getStatus() == 401) {
            String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId();
            throw new MsoAdapterException(error);
        } else {
            throw keystoneErrorToMsoException(e, TOKEN_AUTH);
        }
    } catch (OpenStackConnectException e) {
        MsoIOException me = new MsoIOException(e.getMessage(), e);
        me.addContext(TOKEN_AUTH);
        throw me;
    } catch (RuntimeException e) {
        throw runtimeExceptionToMsoException(e, TOKEN_AUTH);
    }
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) Access(com.woorea.openstack.keystone.model.Access) KeystoneAuthHolder(org.onap.so.cloud.authentication.KeystoneAuthHolder) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ServiceEndpointNotFoundException(org.onap.so.cloud.authentication.ServiceEndpointNotFoundException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) CloudSite(org.onap.so.db.catalog.beans.CloudSite) MsoIOException(org.onap.so.openstack.exceptions.MsoIOException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 9 with MsoAdapterException

use of org.onap.so.openstack.exceptions.MsoAdapterException in project so by onap.

the class MsoNetworkAdapterImpl method mergeSubnetsAIC3.

/**
 * Subnet Output structure from Juniper { "ipam_subnets": [ { "subnet": { "ip_prefix": "10.100.1.0",
 * "ip_prefix_len": 28 }, "addr_from_start": null, "enable_dhcp": false, "default_gateway": "10.100.1.1",
 * "dns_nameservers": [], "dhcp_option_list": null, "subnet_uuid": "10391fbf-6b9c-4160-825d-2d018b7649cf",
 * "allocation_pools": [ { "start": "10.100.1.3", "end": "10.100.1.5" }, { "start": "10.100.1.6", "end":
 * "10.100.1.9" } ], "host_routes": null, "dns_server_address": "10.100.1.13", "subnet_name":
 * "subnet_MsoNW1_692c9032-e1a2-4d64-828c-7b9a4fcc05b0" }, { "subnet": { "ip_prefix": "10.100.2.16",
 * "ip_prefix_len": 28 }, "addr_from_start": null, "enable_dhcp": true, "default_gateway": "10.100.2.17",
 * "dns_nameservers": [], "dhcp_option_list": null, "subnet_uuid": "c7aac5ea-66fe-443a-85f9-9c38a608c0f6",
 * "allocation_pools": [ { "start": "10.100.2.18", "end": "10.100.2.20" } ], "host_routes": null,
 * "dns_server_address": "10.100.2.29", "subnet_name": "subnet_MsoNW1_692c9032-e1a2-4d64-828c-7b9a4fcc05b1" } ],
 * "host_routes": null }
 **
 */
private String mergeSubnetsAIC3(String heatTemplate, List<Subnet> subnets, Map<String, Object> stackParams) throws MsoException {
    // Resource Property
    List<ContrailSubnet> cslist = new ArrayList<>();
    for (Subnet subnet : subnets) {
        logger.debug("Input Subnet:{}", subnet);
        ContrailSubnet cs = new ContrailSubnetMapper(subnet).map();
        logger.debug("Contrail Subnet:{}", cs);
        cslist.add(cs);
    }
    JsonNode node = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        node = mapper.convertValue(cslist, JsonNode.class);
        String jsonString = mapper.writeValueAsString(cslist);
        logger.debug("Json Subnet List:{}", jsonString);
    } catch (Exception e) {
        String error = "Error creating JsonNode from input subnets";
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_MARSHING_ERROR, ErrorCode.DataError.getValue(), error, e);
        throw new MsoAdapterException(error);
    }
    // update parameters
    if (node != null) {
        stackParams.put("subnet_list", node);
    }
    // Outputs - All subnets are in one ipam_subnets structure
    String outputTempl = "  subnet:\n" + "    description: Openstack subnet identifier\n" + "    value: { get_attr: [network, network_ipam_refs, 0, attr]}\n";
    // append outputs in heatTemplate
    int outputsIdx = heatTemplate.indexOf("outputs:");
    heatTemplate = insertStr(heatTemplate, outputTempl, outputsIdx + 8);
    logger.debug("Template updated with all AIC3.0 subnets:{}", heatTemplate);
    return heatTemplate;
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ContrailSubnetMapper(org.onap.so.adapters.network.mappers.ContrailSubnetMapper) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException)

Example 10 with MsoAdapterException

use of org.onap.so.openstack.exceptions.MsoAdapterException in project so by onap.

the class MsoNetworkAdapterImpl method mergePolicyRefs.

/**
 * policyRef_list structure in stackParams [ { "network_policy_refs_data_sequence": {
 * "network_policy_refs_data_sequence_major": "1", "network_policy_refs_data_sequence_minor": "0" } }, {
 * "network_policy_refs_data_sequence": { "network_policy_refs_data_sequence_major": "2",
 * "network_policy_refs_data_sequence_minor": "0" } } ]
 */
private void mergePolicyRefs(List<String> pFqdns, Map<String, Object> stackParams) throws MsoException {
    // Resource Property
    List<ContrailPolicyRef> prlist = new ArrayList<>();
    int index = 1;
    if (pFqdns != null) {
        for (String pf : pFqdns) {
            if (!commonUtils.isNullOrEmpty(pf)) {
                ContrailPolicyRef pr = new ContrailPolicyRef();
                ContrailPolicyRefSeq refSeq = new ContrailPolicyRefSeq(String.valueOf(index), "0");
                pr.setSeq(refSeq);
                index++;
                logger.debug("Contrail PolicyRefs Data:{}", pr);
                prlist.add(pr);
            }
        }
    } else {
        String error = "Null pFqdns at start of mergePolicyRefs";
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_MARSHING_ERROR, ErrorCode.BusinessProcessError.getValue(), error);
        throw new MsoAdapterException(error);
    }
    JsonNode node = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        node = mapper.convertValue(prlist, JsonNode.class);
        String jsonString = mapper.writeValueAsString(prlist);
        logger.debug("Json PolicyRefs Data:{}", jsonString);
    } catch (Exception e) {
        String error = "Error creating JsonNode for policyRefs Data";
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_MARSHING_ERROR, ErrorCode.BusinessProcessError.getValue(), error, e);
        throw new MsoAdapterException(error);
    }
    // update parameters
    if (pFqdns != null && node != null) {
        StringBuilder buf = new StringBuilder();
        String sep = "";
        for (String pf : pFqdns) {
            if (!commonUtils.isNullOrEmpty(pf)) {
                buf.append(sep).append(pf);
                sep = ",";
            }
        }
        String csl = buf.toString();
        stackParams.put("policy_refs", csl);
        stackParams.put("policy_refsdata", node);
    }
    logger.debug("StackParams updated with policy refs");
    return;
}
Also used : MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ContrailPolicyRefSeq(org.onap.so.adapters.network.beans.ContrailPolicyRefSeq) ContrailPolicyRef(org.onap.so.adapters.network.beans.ContrailPolicyRef) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException)

Aggregations

MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)11 MsoException (org.onap.so.openstack.exceptions.MsoException)6 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)4 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)4 CloudIdentity (org.onap.so.db.catalog.beans.CloudIdentity)4 Keystone (com.woorea.openstack.keystone.Keystone)3 Access (com.woorea.openstack.keystone.model.Access)3 MsoIOException (org.onap.so.openstack.exceptions.MsoIOException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Authentication (com.woorea.openstack.keystone.model.Authentication)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 BaseTest (org.onap.so.BaseTest)2 ContrailSubnet (org.onap.so.adapters.network.beans.ContrailSubnet)2 NetworkException (org.onap.so.adapters.network.exceptions.NetworkException)2 KeystoneAuthHolder (org.onap.so.cloud.authentication.KeystoneAuthHolder)2 ServiceEndpointNotFoundException (org.onap.so.cloud.authentication.ServiceEndpointNotFoundException)2 CloudSite (org.onap.so.db.catalog.beans.CloudSite)2 Subnet (org.onap.so.openstack.beans.Subnet)2