blob: 4e5fb6b6e3a571bc3ff19e1b1548b63c1a0dc6df [file] [log] [blame]
Antonio Marsico4f68ec92017-03-09 11:16:32 +01001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.intent.constraint;
17
18import org.onosproject.net.intent.ConnectivityIntent;
19import org.onosproject.net.intent.Intent;
20
21/**
22 * Constraint to request a non-disruptive intent reallocation.
23 */
24public final class NonDisruptiveConstraint extends MarkerConstraint {
25
26 private static final NonDisruptiveConstraint NON_DISRUPTIVE_CONSTRAINT = new NonDisruptiveConstraint();
27
28 protected NonDisruptiveConstraint() {
29 }
30
31 /**
32 * Determines whether the intent requires a non-disruptive reallocation.
33 *
34 * @param intent intent to be inspected
35 * @return whether the intent has a NonDisruptiveConstraint
36 */
37 public static boolean requireNonDisruptive(Intent intent) {
38 if (intent instanceof ConnectivityIntent) {
39 ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent;
40 return connectivityIntent.constraints().stream()
41 .anyMatch(p -> p instanceof NonDisruptiveConstraint);
42 }
43 return false;
44 }
45
46 /**
47 * Returns the nonDisruptiveConstraint.
48 *
49 * @return non-disruptive constraint
50 */
51 public static NonDisruptiveConstraint nonDisruptive() {
52 return NON_DISRUPTIVE_CONSTRAINT;
53 }
54
55 @Override
56 public String toString() {
57 return "Non-disruptive reallocation required";
58 }
59}