Fix few code issues
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / validation / ServiceCreateValidation.java
1 /*
2  * Copyright © 2017 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.servicehandler.validation;
10
11 import org.opendaylight.transportpce.common.OperationResult;
12 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
13 import org.opendaylight.transportpce.servicehandler.ServiceInput;
14 import org.opendaylight.transportpce.servicehandler.validation.checks.CheckCoherencyHardSoft;
15 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
16 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerComplianceCheck;
17 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerTxRxCheck;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.RpcActions;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeader;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public final class ServiceCreateValidation {
25     private static final Logger LOG = LoggerFactory.getLogger(ServiceCreateValidation.class);
26
27     public static OperationResult validateServiceCreateRequest(ServiceInput input, RpcActions rpcActions) {
28         /*
29          * Upon receipt of service
30          * -create RPC, service header and sdnc
31          * -request header compliancy are verified.
32          */
33         LOG.debug("checking Service Compliance ...");
34         String serviceNmame = input.getServiceName();
35         SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
36         ConnectionType conType = input.getConnectionType();
37         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check(
38                 serviceNmame, sdncRequestHeader, conType, rpcActions, true, true);
39         if (serviceHandlerCheckResult.hasPassed()) {
40             LOG.debug("Service request compliant !");
41         } else {
42             return OperationResult.failed(serviceHandlerCheckResult.getMessage());
43         }
44         /*
45          * If compliant, service-request parameters are verified in order to
46          * check if there is no missing parameter that prevents calculating
47          * a path and implement a service.
48          */
49         LOG.debug("checking Tx/Rx Info for AEnd ...");
50         ComplianceCheckResult txrxCheckAEnd = ServicehandlerTxRxCheck.check(input.getServiceAEnd(),
51                 ServiceEndpointType.SERVICEAEND);
52         if (txrxCheckAEnd.hasPassed()) {
53             LOG.debug("Tx/Rx Info for AEnd checked !");
54         } else {
55             return OperationResult.failed(txrxCheckAEnd.getMessage());
56         }
57
58         LOG.debug("checking Tx/Rx Info for ZEnd ...");
59         ComplianceCheckResult txrxCheckZEnd = ServicehandlerTxRxCheck.check(input.getServiceZEnd(),
60                 ServiceEndpointType.SERVICEZEND);
61         if (txrxCheckZEnd.hasPassed()) {
62             LOG.debug("Tx/Rx Info for ZEnd checked");
63             /*
64              * If OK, common-id is verified in order to see if there is
65              * no routing policy provided. If yes, the routing
66              * constraints of the policy are recovered and coherency
67              * with hard/soft constraints provided in the input of the
68              * RPC.
69              */
70         } else {
71             return OperationResult.failed(txrxCheckZEnd.getMessage());
72         }
73
74         if (input.getCommonId() != null) {
75             LOG.debug("Common-id specified");
76             // Check coherency with hard/soft constraints
77             if (CheckCoherencyHardSoft.check(input.getHardConstraints(), input.getSoftConstraints())) {
78                 LOG.debug("hard/soft constraints coherent !");
79             } else {
80                 return OperationResult.failed("hard/soft constraints are not coherent !");
81             }
82         } else {
83             LOG.warn("Common-id not specified !");
84         }
85         return OperationResult.ok("Validation successful.");
86     }
87
88     private ServiceCreateValidation() {
89     }
90
91 }