CDS: Add stress test RPC to the cars model
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / strategy / EditStrategyType.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, 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.controller.config.facade.xml.strategy;
10
11 import java.util.EnumSet;
12 import java.util.Set;
13 import org.opendaylight.controller.config.facade.xml.exception.OperationNotPermittedException;
14 import org.opendaylight.controller.config.util.xml.DocumentedException;
15
16 public enum EditStrategyType {
17     // can be default
18     merge, replace, none,
19     // additional per element
20     delete, remove;
21
22     private static final Set<EditStrategyType> defaultStrats = EnumSet.of(merge, replace, none);
23
24     public static EditStrategyType getDefaultStrategy() {
25         return merge;
26     }
27
28     public boolean isEnforcing() {
29         switch (this) {
30         case merge:
31         case none:
32         case remove:
33         case delete:
34             return false;
35         case replace:
36             return true;
37
38         default:
39             throw new IllegalStateException("Default edit strategy can be only of value " + defaultStrats + " but was "
40                     + this);
41         }
42     }
43     public static void compareParsedStrategyToDefaultEnforcing(EditStrategyType parsedStrategy,
44                                                                   EditStrategyType defaultStrategy) throws OperationNotPermittedException {
45         if (defaultStrategy.isEnforcing()) {
46             if (parsedStrategy != defaultStrategy){
47                 throw new OperationNotPermittedException(String.format("With "
48                         + defaultStrategy
49                         + " as default-operation operations on module elements are not permitted since the default option is restrictive"),
50                         DocumentedException.ErrorType.application,
51                         DocumentedException.ErrorTag.operation_failed,
52                         DocumentedException.ErrorSeverity.error);
53             }
54         }
55
56     }
57     public EditConfigStrategy getFittingStrategy() {
58         switch (this) {
59         case merge:
60             return new MergeEditConfigStrategy();
61         case replace:
62             return new ReplaceEditConfigStrategy();
63         case delete:
64             return new DeleteEditConfigStrategy();
65         case remove:
66             return new RemoveEditConfigStrategy();
67         case none:
68             return new NoneEditConfigStrategy();
69         default:
70             throw new UnsupportedOperationException("Unimplemented edit config strategy" + this);
71         }
72     }
73 }