use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class RollbackService method executeExternalTask.
public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
mdcSetup.setupMDC(externalTask);
logger.debug("Starting External Task Rollback Service");
Map<String, Object> variables = new HashMap<>();
boolean success = false;
boolean pollRollbackStatus = false;
try {
String xmlRequest = externalTask.getVariable("openstackAdapterTaskRequest");
if (xmlRequest != null) {
Optional<String> requestType = findRequestType(xmlRequest);
if ("createVolumeGroupRequest".equals(requestType.get())) {
logger.debug("Executing External Task Rollback Service for Create Volume Group");
CreateVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class);
boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
if (!isMulticloud) {
vnfAdapterImpl.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVolumeGroupName(), null, req.getMsoRequest(), new Holder<>());
pollRollbackStatus = true;
success = true;
} else {
vnfPluginImpl.deleteVnf(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVolumeGroupName(), req.getMsoRequest());
pollRollbackStatus = false;
success = true;
}
} else if ("createVfModuleRequest".equals(requestType.get())) {
logger.debug("Executing External Task Rollback Service for Create Vf Module");
CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class);
boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
if (!isMulticloud) {
vnfAdapterImpl.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVfModuleName(), req.getModelCustomizationUuid(), req.getMsoRequest(), new Holder<>());
pollRollbackStatus = true;
success = true;
} else {
pollRollbackStatus = false;
success = true;
}
} else if ("createNetworkRequest".equals(requestType.get())) {
logger.debug("Executing External Task Rollback Service for Create Network");
CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
networkAdapterImpl.deleteNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkName(), req.getMsoRequest());
pollRollbackStatus = true;
success = true;
}
}
} catch (Exception e) {
logger.error("Error during External Task Rollback Service", e);
}
variables.put("OpenstackRollbackSuccess", success);
variables.put("rollbackPerformed", true);
variables.put("PollRollbackStatus", pollRollbackStatus);
if (success) {
externalTaskService.complete(externalTask, variables);
logger.debug("The External Task Id: {} Successful", externalTask.getId());
} else {
logger.debug("The External Task Id: {} Failed. Not Retrying", externalTask.getId());
externalTaskService.complete(externalTask, variables);
}
}
use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class NetworkAdapterClientIT method createNetworkTestThrowException.
@Test(expected = NetworkAdapterClientException.class)
public void createNetworkTestThrowException() throws NetworkAdapterClientException, JsonProcessingException {
CreateNetworkRequest request = new CreateNetworkRequest();
request.setCloudSiteId(TESTING_ID);
CreateNetworkError mockResponse = new CreateNetworkError();
mockResponse.setMessage("Error in create network");
wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(mapper.writeValueAsString(mockResponse)).withStatus(500)));
client.createNetwork(request);
}
use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class StackService method createNetwork.
private void createNetwork(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success, MutableBoolean os3) throws NetworkException {
CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
HashMap<String, String> params = (HashMap<String, String>) req.getNetworkParams();
if (params == null) {
params = new HashMap<>();
}
String shared = null;
String external = null;
String physicalNetworkName = null;
List<Integer> vlans = null;
List<RouteTarget> routeTargets = null;
List<String> fqdns = null;
List<String> routeTable = null;
if (params.containsKey(SHARED))
shared = params.get(SHARED);
if (params.containsKey(EXTERNAL))
external = params.get(EXTERNAL);
if (req.isContrailRequest()) {
ContrailNetwork ctn = req.getContrailNetwork();
if (ctn == null) {
ctn = new ContrailNetwork();
req.setContrailNetwork(ctn);
}
if (shared == null && ctn.getShared() != null) {
shared = ctn.getShared();
}
if (shared == null && ctn.getExternal() != null) {
external = ctn.getExternal();
}
routeTargets = req.getContrailNetwork().getRouteTargets();
fqdns = req.getContrailNetwork().getPolicyFqdns();
routeTable = req.getContrailNetwork().getRouteTableFqdns();
} else {
ProviderVlanNetwork pvn = req.getProviderVlanNetwork();
if (pvn == null) {
pvn = new ProviderVlanNetwork();
req.setProviderVlanNetwork(pvn);
}
physicalNetworkName = req.getProviderVlanNetwork().getPhysicalNetworkName();
vlans = req.getProviderVlanNetwork().getVlans();
}
networkAdapterImpl.createNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkName(), physicalNetworkName, vlans, routeTargets, shared, external, req.getFailIfExists(), false, req.getSubnets(), fqdns, routeTable, req.getMsoRequest(), canonicalStackId, os3);
success.setTrue();
backout.setValue(req.getBackout());
}
use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class NetworkAdapterCreateTasks method createNetwork.
public void createNetwork(BuildingBlockExecution execution) {
execution.setVariable("networkAdapterCreateRollback", false);
try {
GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
Map<String, String> userInput = gBBInput.getUserInput();
String cloudRegionPo = execution.getVariable("cloudRegionPo");
CreateNetworkRequest createNetworkRequest = networkAdapterObjectMapper.createNetworkRequestMapper(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, userInput, cloudRegionPo, gBBInput.getCustomer());
execution.setVariable("networkAdapterRequest", createNetworkRequest.toXmlString());
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class NetworkAdapterObjectMapperTest method buildCreateNetworkRequestFromBbobjectTest.
@Test
public void buildCreateNetworkRequestFromBbobjectTest() throws Exception {
String cloudRegionPo = "cloudRegionPo";
CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest();
expectedCreateNetworkRequest.setCloudSiteId(cloudRegionPo);
expectedCreateNetworkRequest.setTenantId(cloudRegion.getTenantId());
expectedCreateNetworkRequest.setNetworkId(l3Network.getNetworkId());
expectedCreateNetworkRequest.setNetworkName(l3Network.getNetworkName());
expectedCreateNetworkRequest.setNetworkType(l3Network.getNetworkType());
expectedCreateNetworkRequest.setBackout(false);
expectedCreateNetworkRequest.setFailIfExists(false);
expectedCreateNetworkRequest.setNetworkTechnology("CONTRAIL");
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId(requestContext.getMsoRequestId());
msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
expectedCreateNetworkRequest.setMsoRequest(msoRequest);
expectedCreateNetworkRequest.setSkipAAI(true);
HashMap<String, String> networkParams = new HashMap<String, String>();
networkParams.put("shared", "true");
networkParams.put("external", "false");
networkParams.put("testUserInputKey", "testUserInputValue");
expectedCreateNetworkRequest.setNetworkParams(networkParams);
expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId");
Subnet openstackSubnet = new Subnet();
HostRoute hostRoute = new HostRoute();
hostRoute.setHostRouteId("hostRouteId");
hostRoute.setNextHop("nextHop");
hostRoute.setRoutePrefix("routePrefix");
openstackSubnet.getHostRoutes().add(hostRoute);
List<Subnet> subnetList = new ArrayList<Subnet>();
subnetList.add(openstackSubnet);
l3Network.getSubnets().add(openstackSubnet);
l3Network.setNetworkTechnology("Contrail");
l3Network.setIsSharedNetwork(true);
l3Network.setIsExternalNetwork(false);
doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint();
doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid();
CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer);
assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("contrailRequest").ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("messageId"));
}
Aggregations