fix some compilation warnings
[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.validation.checks.CheckCoherencyHardSoft;
14 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
15 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerCompliancyCheck;
16 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerTxRxCheck;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
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(ServiceCreateInput input) {
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 Compliancy ...");
34         try {
35             String serviceNmame = input.getServiceName();
36             SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
37             ConnectionType conType = input.getConnectionType();
38             ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerCompliancyCheck.check(
39                     serviceNmame, sdncRequestHeader, conType, RpcActions.ServiceCreate, true, true);
40             if (serviceHandlerCheckResult.hasPassed()) {
41                 LOG.debug("Service request compliant !");
42             } else {
43                 return OperationResult.failed(serviceHandlerCheckResult.getMessage());
44             }
45             /*
46              * If compliant, service-request parameters are verified in order to
47              * check if there is no missing parameter that prevents calculating
48              * a path and implement a service.
49              */
50             LOG.debug("checking Tx/Rx Info for AEnd ...");
51             ComplianceCheckResult txrxCheckAEnd = ServicehandlerTxRxCheck.check(input.getServiceAEnd(),
52                     ServiceEndpointType.SERVICEAEND);
53             if (txrxCheckAEnd.hasPassed()) {
54                 LOG.debug("Tx/Rx Info for AEnd checked !");
55             } else {
56                 return OperationResult.failed(txrxCheckAEnd.getMessage());
57             }
58
59             LOG.debug("checking Tx/Rx Info for ZEnd ...");
60             ComplianceCheckResult txrxCheckZEnd = ServicehandlerTxRxCheck.check(input.getServiceZEnd(),
61                     ServiceEndpointType.SERVICEZEND);
62             if (txrxCheckZEnd.hasPassed()) {
63                 LOG.debug("Tx/Rx Info for ZEnd checked");
64                 /*
65                  * If OK, common-id is verified in order to see if there is
66                  * no routing policy provided. If yes, the routing
67                  * constraints of the policy are recovered and coherency
68                  * with hard/soft constraints provided in the input of the
69                  * RPC.
70                  */
71             } else {
72                 return OperationResult.failed(txrxCheckZEnd.getMessage());
73             }
74
75             if (input.getCommonId() != null) {
76                 LOG.debug("Common-id specified");
77                 // Check coherency with hard/soft constraints
78                 if (CheckCoherencyHardSoft.check(input.getHardConstraints(), input.getSoftConstraints())) {
79                     LOG.debug("hard/soft constraints coherent !");
80                 } else {
81                     return OperationResult.failed("hard/soft constraints are not coherent !");
82                 }
83             } else {
84                 LOG.warn("Common-id not specified !");
85             }
86         } catch (NullPointerException e) {
87             LOG.error("one of input parameter is null ",e);
88             OperationResult.failed("one of input parameter is null.");
89         }
90         return OperationResult.ok("Validation successful.");
91     }
92
93     public ServiceCreateValidation() {
94     }
95
96 }