+ @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+ value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "call in call() method")
+ private boolean manageServicePathCreation(ServiceImplementationRequestInput input, String serviceType) {
+ ServicePathInputData servicePathInputDataAtoZ = ModelMappingUtils
+ .rendererCreateServiceInputAToZ(input.getServiceName(), input.getPathDescription(), Action.Create);
+ ServicePathInputData servicePathInputDataZtoA = ModelMappingUtils
+ .rendererCreateServiceInputZToA(input.getServiceName(), input.getPathDescription(), Action.Create);
+ // Rollback should be same for all conditions, so creating a new one
+ RollbackProcessor rollbackProcessor = new RollbackProcessor();
+ List<DeviceRenderingResult> renderingResults =
+ deviceRendering(rollbackProcessor, servicePathInputDataAtoZ, servicePathInputDataZtoA);
+ if (rollbackProcessor.rollbackAllIfNecessary() > 0 || renderingResults.isEmpty()) {
+ sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest,
+ input.getServiceName(), RpcStatusEx.Failed, DEVICE_RENDERING_ROLL_BACK_MSG);
+ return false;
+ }
+ ServicePowerSetupInput olmPowerSetupInputAtoZ =
+ ModelMappingUtils.createServicePowerSetupInput(renderingResults.get(0).getOlmList(), input);
+ ServicePowerSetupInput olmPowerSetupInputZtoA =
+ ModelMappingUtils.createServicePowerSetupInput(renderingResults.get(1).getOlmList(), input);
+ olmPowerSetup(rollbackProcessor, olmPowerSetupInputAtoZ, olmPowerSetupInputZtoA);
+ if (rollbackProcessor.rollbackAllIfNecessary() > 0) {
+ sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest,
+ input.getServiceName(), RpcStatusEx.Failed, OLM_ROLL_BACK_MSG);
+ return false;
+ }
+ // run service activation test twice - once on source node and once on
+ // destination node
+ List<Nodes> nodes = servicePathInputDataAtoZ.getServicePathInput().getNodes();
+ if ((nodes == null) || (nodes.isEmpty())) {
+ return false;
+ }
+
+ Nodes sourceNode = nodes.get(0);
+ Nodes destNode = nodes.get(nodes.size() - 1);
+ String srcNetworkTp =
+ sourceNode.getDestTp().contains(StringConstants.NETWORK_TOKEN)
+ ? sourceNode.getDestTp()
+ : sourceNode.getSrcTp();
+ String dstNetowrkTp =
+ destNode.getDestTp().contains(StringConstants.NETWORK_TOKEN)
+ ? destNode.getDestTp()
+ : destNode.getSrcTp();
+
+ if (!isServiceActivated(sourceNode.getNodeId(), srcNetworkTp)
+ || !isServiceActivated(destNode.getNodeId(), dstNetowrkTp)) {
+ rollbackProcessor.rollbackAll();
+ sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest,
+ input.getServiceName(), RpcStatusEx.Failed,
+ "Service activation test failed.");
+ return false;
+ }
+ List<LinkTp> otnLinkTerminationPoints = new ArrayList<>();
+ renderingResults.forEach(rr -> otnLinkTerminationPoints.addAll(rr.getOtnLinkTps()));
+ Link notifLink = createLinkForNotif(otnLinkTerminationPoints);
+
+ sendNotificationsWithPathDescription(ServicePathNotificationTypes.ServiceImplementationRequest,
+ input.getServiceName(), RpcStatusEx.Successful, OPERATION_SUCCESSFUL, input.getPathDescription(),
+ notifLink, null, serviceType);
+ return true;
+ }
+
+ @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+ value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "call in call() method")
+ private boolean manageServicePathDeletion(String serviceName, PathDescription pathDescription, String serviceType)
+ throws InterruptedException {
+ ServicePathInputData servicePathInputDataAtoZ =
+ ModelMappingUtils.rendererCreateServiceInputAToZ(serviceName, pathDescription, Action.Delete);
+ ServicePathInputData servicePathInputDataZtoA =
+ ModelMappingUtils.rendererCreateServiceInputZToA(serviceName, pathDescription, Action.Delete);
+ // OLM turn down power
+ try {
+ LOG.debug(TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG);
+ sendNotifications(ServicePathNotificationTypes.ServiceDelete, serviceName,
+ RpcStatusEx.Pending, TURNING_DOWN_POWER_ON_A_TO_Z_PATH_MSG);
+ ServicePowerTurndownOutput atozPowerTurndownOutput = olmPowerTurndown(servicePathInputDataAtoZ);
+ // TODO add some flag rather than string
+ if (FAILED.equals(atozPowerTurndownOutput.getResult())) {
+ LOG.error("Service power turndown failed on A-to-Z path for service {}!", serviceName);
+ sendNotifications(ServicePathNotificationTypes.ServiceDelete, serviceName, RpcStatusEx.Failed,
+ "Service power turndown failed on A-to-Z path for service");
+ return false;
+ }
+ LOG.debug("Turning down power on Z-to-A path");
+ sendNotifications(ServicePathNotificationTypes.ServiceDelete, serviceName, RpcStatusEx.Pending,
+ "Turning down power on Z-to-A path");
+ ServicePowerTurndownOutput ztoaPowerTurndownOutput = olmPowerTurndown(servicePathInputDataZtoA);
+ // TODO add some flag rather than string
+ if (FAILED.equals(ztoaPowerTurndownOutput.getResult())) {
+ LOG.error("Service power turndown failed on Z-to-A path for service {}!", serviceName);
+ sendNotifications(ServicePathNotificationTypes.ServiceDelete, serviceName, RpcStatusEx.Failed,
+ "Service power turndown failed on Z-to-A path for service");
+ return false;
+ }
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ LOG.error("Error while turning down power!", e);
+ return false;
+ }
+ // delete service path with renderer
+ LOG.info("Deleting service path via renderer");
+ sendNotifications(ServicePathNotificationTypes.ServiceDelete, serviceName, RpcStatusEx.Pending,
+ "Deleting service path via renderer");
+ RollbackProcessor rollbackProcessor = new RollbackProcessor();
+ List<DeviceRenderingResult> renderingResults =
+ deviceRendering(rollbackProcessor, servicePathInputDataAtoZ, servicePathInputDataZtoA);
+ List<LinkTp> otnLinkTerminationPoints = new ArrayList<>();
+ renderingResults.forEach(rr -> otnLinkTerminationPoints.addAll(rr.getOtnLinkTps()));
+ Link notifLink = createLinkForNotif(otnLinkTerminationPoints);
+
+ sendNotificationsWithPathDescription(ServicePathNotificationTypes.ServiceDelete,
+ serviceName, RpcStatusEx.Successful, OPERATION_SUCCESSFUL, pathDescription, notifLink, null, serviceType);
+ return true;
+ }
+
+ @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+ value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "call in call() method")
+ private boolean manageOtnServicePathCreation(ServiceImplementationRequestInput input, String serviceType,
+ Uint32 serviceRate) {
+ // This is A-Z side
+ OtnServicePathInput otnServicePathInputAtoZ = ModelMappingUtils
+ .rendererCreateOtnServiceInput(input.getServiceName(), Action.Create,
+ input.getServiceAEnd().getServiceFormat().getName(),
+ serviceRate,
+ input.getPathDescription(), true);
+ // This is Z-A side
+ OtnServicePathInput otnServicePathInputZtoA = ModelMappingUtils
+ .rendererCreateOtnServiceInput(input.getServiceName(), Action.Create,
+ input.getServiceZEnd().getServiceFormat().getName(),
+ serviceRate,
+ input.getPathDescription(), false);
+ // Rollback should be same for all conditions, so creating a new one
+ RollbackProcessor rollbackProcessor = new RollbackProcessor();
+ List<OtnDeviceRenderingResult> renderingResults =
+ otnDeviceRendering(rollbackProcessor, otnServicePathInputAtoZ, otnServicePathInputZtoA, serviceType);
+ if (rollbackProcessor.rollbackAllIfNecessary() > 0) {
+ rollbackProcessor.rollbackAll();
+ sendNotifications(ServicePathNotificationTypes.ServiceImplementationRequest,
+ input.getServiceName(), RpcStatusEx.Failed, DEVICE_RENDERING_ROLL_BACK_MSG);
+ return false;
+ }
+ List<LinkTp> otnLinkTerminationPoints = new ArrayList<>();
+ renderingResults.forEach(rr -> otnLinkTerminationPoints.addAll(rr.getOtnLinkTps()));
+ Link notifLink = createLinkForNotif(otnLinkTerminationPoints);
+ List<String> allSupportLinks = ModelMappingUtils.getLinksFromServicePathDescription(input.getPathDescription());
+ List<String> supportedLinks = getSupportedLinks(allSupportLinks, serviceType);
+
+ sendNotificationsWithPathDescription(ServicePathNotificationTypes.ServiceImplementationRequest,
+ input.getServiceName(), RpcStatusEx.Successful, OPERATION_SUCCESSFUL, input.getPathDescription(),
+ notifLink, supportedLinks, serviceType);
+ return true;
+ }
+
+ @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+ value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "call in call() method")
+ private boolean manageOtnServicePathDeletion(String serviceName, PathDescription pathDescription,
+ Services service, String serviceType) {
+ // This is A-Z side
+ OtnServicePathInput otnServicePathInputAtoZ = ModelMappingUtils
+ .rendererCreateOtnServiceInput(serviceName, Action.Delete,
+ service.getServiceAEnd().getServiceFormat().getName(),
+ service.getServiceAEnd().getServiceRate(),
+ pathDescription, true);
+ // This is Z-A side
+ OtnServicePathInput otnServicePathInputZtoA = ModelMappingUtils
+ .rendererCreateOtnServiceInput(serviceName, Action.Delete,
+ service.getServiceZEnd().getServiceFormat().getName(),
+ service.getServiceAEnd().getServiceRate(),
+ pathDescription, false);
+ LOG.info("Deleting otn-service path {} via renderer", serviceName);
+ sendNotifications(ServicePathNotificationTypes.ServiceDelete, serviceName, RpcStatusEx.Pending,
+ "Deleting otn-service path via renderer");
+
+ RollbackProcessor rollbackProcessor = new RollbackProcessor();
+ List<OtnDeviceRenderingResult> renderingResults =
+ otnDeviceRendering(rollbackProcessor, otnServicePathInputAtoZ, otnServicePathInputZtoA, serviceType);
+
+ List<LinkTp> otnLinkTerminationPoints = new ArrayList<>();
+ renderingResults.forEach(rr -> otnLinkTerminationPoints.addAll(rr.getOtnLinkTps()));
+ Link notifLink = createLinkForNotif(otnLinkTerminationPoints);
+ List<String> allSupportLinks = ModelMappingUtils.getLinksFromServicePathDescription(pathDescription);
+ List<String> supportedLinks = getSupportedLinks(allSupportLinks, serviceType);
+
+ sendNotificationsWithPathDescription(ServicePathNotificationTypes.ServiceDelete,
+ serviceName, RpcStatusEx.Successful, OPERATION_SUCCESSFUL, pathDescription, notifLink, supportedLinks,
+ serviceType);
+ return true;
+ }
+
+ /**
+ * Send renderer notification.
+ * @param servicePathNotificationTypes ServicePathNotificationTypes
+ * @param serviceName String
+ * @param rpcStatusEx RpcStatusEx
+ * @param message String
+ */
+ private void sendNotifications(ServicePathNotificationTypes servicePathNotificationTypes, String serviceName,
+ RpcStatusEx rpcStatusEx, String message) {
+ Notification notification = buildNotification(servicePathNotificationTypes, serviceName, rpcStatusEx, message,
+ null, null, null, null);
+ send(notification);
+ }
+
+ /**
+ * Send renderer notification with path description information.
+ * @param servicePathNotificationTypes ServicePathNotificationTypes
+ * @param serviceName String
+ * @param rpcStatusEx RpcStatusEx
+ * @param message String
+ * @param pathDescription PathDescription
+ */
+ private void sendNotificationsWithPathDescription(ServicePathNotificationTypes servicePathNotificationTypes,
+ String serviceName, RpcStatusEx rpcStatusEx, String message, PathDescription pathDescription,
+ Link notifLink, List<String> supportedLinks, String serviceType) {
+ Notification notification = buildNotification(servicePathNotificationTypes, serviceName, rpcStatusEx, message,
+ pathDescription, notifLink, supportedLinks, serviceType);
+ send(notification);
+ }
+
+ /**
+ * Build notification containing path description information.
+ * @param servicePathNotificationTypes ServicePathNotificationTypes
+ * @param serviceName String
+ * @param rpcStatusEx RpcStatusEx
+ * @param message String
+ * @param pathDescription PathDescription
+ * @return notification with RendererRpcResultSp type.
+ */
+ private RendererRpcResultSp buildNotification(ServicePathNotificationTypes servicePathNotificationTypes,
+ String serviceName, RpcStatusEx rpcStatusEx, String message, PathDescription pathDescription,
+ Link notifLink, List<String> supportedLinks, String serviceType) {
+ RendererRpcResultSpBuilder builder = new RendererRpcResultSpBuilder()
+ .setNotificationType(servicePathNotificationTypes).setServiceName(serviceName).setStatus(rpcStatusEx)
+ .setStatusMessage(message)
+ .setServiceType(serviceType);
+ if (pathDescription != null) {
+ builder.setAToZDirection(pathDescription.getAToZDirection())
+ .setZToADirection(pathDescription.getZToADirection());
+ }
+ if (notifLink != null) {
+ builder.setLink(notifLink);
+ }
+ if (supportedLinks != null) {
+ builder.setLinkId(supportedLinks);
+ }
+ return builder.build();
+ }
+
+ /**
+ * Send renderer notification.
+ * @param notification Notification
+ */
+ private void send(Notification notification) {
+ try {
+ LOG.info("Sending notification {}", notification);
+ notificationPublishService.putNotification(notification);
+ } catch (InterruptedException e) {
+ LOG.info("notification offer rejected: ", e);
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ private Link createLinkForNotif(List<LinkTp> otnLinkTerminationPoints) {
+ if (otnLinkTerminationPoints == null || otnLinkTerminationPoints.size() != 2) {
+ return null;
+ }
+ return new LinkBuilder()
+ .setATermination(new ATerminationBuilder()
+ .setNodeId(otnLinkTerminationPoints.get(0).getNodeId())
+ .setTpId(otnLinkTerminationPoints.get(0).getTpId())
+ .build())
+ .setZTermination(new ZTerminationBuilder()
+ .setNodeId(otnLinkTerminationPoints.get(1).getNodeId())
+ .setTpId(otnLinkTerminationPoints.get(1).getTpId())
+ .build())
+ .build();
+ }
+
+ private List<String> getSupportedLinks(List<String> allSupportLinks, String serviceType) {
+ switch (serviceType) {
+ case StringConstants.SERVICE_TYPE_10GE:
+ case StringConstants.SERVICE_TYPE_1GE:
+ return allSupportLinks.stream()
+ .filter(lk -> lk.startsWith(OtnLinkType.ODTU4.getName())).collect(Collectors.toList());
+ case StringConstants.SERVICE_TYPE_100GE_M:
+ return allSupportLinks.stream()
+ .filter(lk -> lk.startsWith(OtnLinkType.ODUC4.getName())).collect(Collectors.toList());
+ case StringConstants.SERVICE_TYPE_ODU4:
+ case StringConstants.SERVICE_TYPE_100GE_S:
+ return allSupportLinks.stream()
+ .filter(lk -> lk.startsWith(OtnLinkType.OTU4.getName())).collect(Collectors.toList());
+ case StringConstants.SERVICE_TYPE_ODUC4:
+ return allSupportLinks.stream()
+ .filter(lk -> lk.startsWith(OtnLinkType.OTUC4.getName())).collect(Collectors.toList());
+ default:
+ return null;
+ }
+ }