8d6d315ceeeb67dc01a25d8147f4dd7005d3e051
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.core.protocols.engdep.messages;
22
23 import org.onap.policy.apex.core.protocols.Message;
24 import org.onap.policy.apex.core.protocols.engdep.EngDepAction;
25 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
26
27 /**
28  * The Class UpdateModel is a message that requests an Apex engine to update its model using the data provided in the
29  * message.
30  *
31  * @author Liam Fallon (liam.fallon@ericsson.com)
32  */
33 public class UpdateModel extends Message {
34     private static final long serialVersionUID = 5885214410842753037L;
35
36     // The reply timeout value for update messages
37     private static final int UPDATE_MODEL_REPLY_TIMEOUT = 30000;
38
39     // Flags indicating whether conflicts in context should be ignored and whether the model should be forced even if it
40     // is incompatible
41     private boolean ignoreConflicts = false;
42     private boolean forceInstall = false;
43
44     /**
45      * Instantiates a new update model message.
46      *
47      * @param engineServiceKey the key of the engine service in which the model of all engines will be updated
48      */
49     public UpdateModel(final AxArtifactKey engineServiceKey) {
50         this(engineServiceKey, null, false, false);
51     }
52
53     /**
54      * Instantiates a new update model message.
55      *
56      * @param engineServiceKey the key of the engine service in which the model of all engines will be updated
57      * @param messageData the message data that indicates to the Apex engine the manner in which its model should be
58      *        updated
59      * @param ignoreConflicts true if conflicts between context in polices is to be ignored
60      * @param force true if the model is to be applied even if it is incompatible with the existing model
61      */
62     public UpdateModel(final AxArtifactKey engineServiceKey, final String messageData, final boolean ignoreConflicts,
63             final boolean force) {
64         super(EngDepAction.UPDATE_MODEL, engineServiceKey, messageData);
65
66         this.ignoreConflicts = ignoreConflicts;
67         this.forceInstall = force;
68
69         // Update messages have a longer timeout
70         setReplyTimeout(UPDATE_MODEL_REPLY_TIMEOUT);
71     }
72
73     /**
74      * Check if context conflicts should be ignored.
75      *
76      * @return true if conflicts should be ignored
77      */
78     public boolean isIgnoreConflicts() {
79         return ignoreConflicts;
80     }
81
82     /**
83      * Check if version checks should be overridden.
84      *
85      * @return true if version checks should be overridden
86      */
87     public boolean isForceInstall() {
88         return forceInstall;
89     }
90
91     /*
92      * (non-Javadoc)
93      *
94      * @see org.onap.policy.apex.core.model.protocols.Message#toString()
95      */
96     @Override
97     public String toString() {
98         return "UpdateModel {" + super.toString() + "}[]";
99     }
100 }