Search in sources :

Example 11 with Subnet

use of org.onap.so.openstack.beans.Subnet in project so by onap.

the class ContrailSubnetMappersTest method createContrailSubnetPoolEmptyTest.

@Test
public void createContrailSubnetPoolEmptyTest() {
    Subnet subnet = new Subnet();
    ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
    ContrailSubnet result = mapper.map();
    List<ContrailSubnetPool> cspools = result.getAllocationPools();
    assertEquals(true, cspools.isEmpty());
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) Test(org.junit.Test)

Example 12 with Subnet

use of org.onap.so.openstack.beans.Subnet in project so by onap.

the class ContrailSubnetMappersTest method createContrailSubnetPoolInvalidTest.

@Test
public void createContrailSubnetPoolInvalidTest() {
    List<Pool> pools = new ArrayList<>();
    Pool pool1 = new Pool();
    pool1.setStart("start1");
    pool1.setEnd("end1");
    Pool pool2 = new Pool();
    pool2.setStart("start2");
    pools.add(pool1);
    pools.add(pool2);
    Subnet subnet = new Subnet();
    subnet.setAllocationPools(pools);
    ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
    ContrailSubnet result = mapper.map();
    List<ContrailSubnetPool> cspools = result.getAllocationPools();
    assertEquals(1, cspools.size());
    assertEquals("start1", cspools.get(0).getStart());
    assertEquals("end1", cspools.get(0).getEnd());
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) ArrayList(java.util.ArrayList) ContrailSubnetPool(org.onap.so.adapters.network.beans.ContrailSubnetPool) Pool(org.onap.so.openstack.beans.Pool) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) Test(org.junit.Test)

Example 13 with Subnet

use of org.onap.so.openstack.beans.Subnet in project so by onap.

the class ContrailSubnetMappersTest method createContrailSubnetHostRoutesTest.

@Test
public void createContrailSubnetHostRoutesTest() {
    List<HostRoute> hostRoutes = new ArrayList<>();
    HostRoute hostRoute1 = new HostRoute();
    hostRoute1.setNextHop("next-hop1");
    hostRoute1.setPrefix("prefix1");
    HostRoute hostRoute2 = new HostRoute();
    hostRoute2.setNextHop("next-hop2");
    hostRoute2.setPrefix("prefix2");
    hostRoutes.add(hostRoute1);
    hostRoutes.add(hostRoute2);
    Subnet subnet = new Subnet();
    subnet.setHostRoutes(hostRoutes);
    ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
    ContrailSubnet result = mapper.map();
    ContrailSubnetHostRoutes routes = result.getHostRoutes();
    assertEquals(2, routes.getHostRoutes().size());
    assertEquals("next-hop2", routes.getHostRoutes().get(1).getNextHop());
    assertEquals("prefix2", routes.getHostRoutes().get(1).getPrefix());
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ArrayList(java.util.ArrayList) ContrailSubnetHostRoutes(org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes) HostRoute(org.onap.so.openstack.beans.HostRoute) ContrailSubnetHostRoute(org.onap.so.adapters.network.beans.ContrailSubnetHostRoute) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) Test(org.junit.Test)

Example 14 with Subnet

use of org.onap.so.openstack.beans.Subnet in project so by onap.

the class MsoNetworkAdapterImpl method getSubnetUUId.

public Map<String, String> getSubnetUUId(String key, Map<String, Object> outputs, List<Subnet> subnets) {
    Map<String, String> sMap = new HashMap<>();
    try {
        Object obj = outputs.get(key);
        ObjectMapper mapper = new ObjectMapper();
        String jStr = mapper.writeValueAsString(obj);
        logger.debug("Subnet_Ipam Output JSON String:{} {}", obj.getClass(), jStr);
        JsonNode rootNode = mapper.readTree(jStr);
        if (rootNode != null) {
            for (JsonNode sNode : rootNode.path("ipam_subnets")) {
                logger.debug("Output Subnet Node {}", sNode);
                String name = sNode.path("subnet_name").textValue();
                String uuid = sNode.path("subnet_uuid").textValue();
                // default
                String aaiId = name;
                // try to find aaiId for name in input subnetList
                if (subnets != null) {
                    for (Subnet subnet : subnets) {
                        if (subnet != null && !commonUtils.isNullOrEmpty(subnet.getSubnetName()) && subnet.getSubnetName().equals(name)) {
                            aaiId = subnet.getSubnetId();
                            break;
                        }
                    }
                }
                // bpmn needs aaid to uuid map
                sMap.put(aaiId, uuid);
            }
        } else {
            logger.error("{} {} null rootNode - cannot get subnet-uuids", MessageEnum.RA_MARSHING_ERROR, ErrorCode.DataError.getValue());
        }
    } catch (Exception e) {
        logger.error("{} {} Exception getting subnet-uuids ", MessageEnum.RA_MARSHING_ERROR, ErrorCode.DataError.getValue(), e);
    }
    logger.debug("Return sMap {}", sMap);
    return sMap;
}
Also used : HashMap(java.util.HashMap) 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 15 with Subnet

use of org.onap.so.openstack.beans.Subnet 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)

Aggregations

Subnet (org.onap.so.openstack.beans.Subnet)15 ContrailSubnet (org.onap.so.adapters.network.beans.ContrailSubnet)14 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)7 ContrailSubnetHostRoute (org.onap.so.adapters.network.beans.ContrailSubnetHostRoute)3 ContrailSubnetHostRoutes (org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes)3 ContrailSubnetPool (org.onap.so.adapters.network.beans.ContrailSubnetPool)3 HostRoute (org.onap.so.openstack.beans.HostRoute)3 Pool (org.onap.so.openstack.beans.Pool)3 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 NetworkException (org.onap.so.adapters.network.exceptions.NetworkException)2 MsoException (org.onap.so.openstack.exceptions.MsoException)2 HashMap (java.util.HashMap)1 PropertyMap (org.modelmapper.PropertyMap)1 ContrailSubnetMapper (org.onap.so.adapters.network.mappers.ContrailSubnetMapper)1