/root> #-------------------------------------------------------------------------------
/root> # ============LICENSE_START=======================================================
/root> #  Copyright (C) 2016-2018 Ericsson. All rights reserved.
/root> # ================================================================================
/root> # Licensed under the Apache License, Version 2.0 (the "License");
/root> # you may not use this file except in compliance with the License.
/root> # You may obtain a copy of the License at
/root> # 
/root> #      http://www.apache.org/licenses/LICENSE-2.0
/root> # 
/root> # Unless required by applicable law or agreed to in writing, software
/root> # distributed under the License is distributed on an "AS IS" BASIS,
/root> # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/root> # See the License for the specific language governing permissions and
/root> # limitations under the License.
/root> # 
/root> # SPDX-License-Identifier: Apache-2.0
/root> # ============LICENSE_END=========================================================
/root> #-------------------------------------------------------------------------------
/root> 
/root> model create name=DecisionMakerPolicyModel
result: SUCCESS

/root> 
/root> schema create name=SimpleStringType  flavour=Java schema=java.lang.String
result: SUCCESS

/root> schema create name=SimpleIntegerType flavour=Java schema=java.lang.Integer
result: SUCCESS

/root> 
/root> album create name=AnswerAlbum scope=policy writable=true schemaName=SimpleStringType
result: SUCCESS

/root> album create name=LastAnswerAlbum scope=policy writable=true schemaName=SimpleIntegerType
result: SUCCESS

/root> 
/root> event create name=AnswerEvent nameSpace=org.onap.policy.apex.domains.decisionmaker source=DCAE target=apex
result: SUCCESS

/root> event parameter create name=AnswerEvent parName=a0 schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=AnswerEvent parName=a1 schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=AnswerEvent parName=a2 schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=AnswerEvent parName=a3 schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=AnswerEvent parName=a4 schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=AnswerEvent parName=a5 schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=AnswerEvent parName=a6 schemaName=SimpleStringType
result: SUCCESS

/root> 
/root> event create name=MakeDecisionEvent nameSpace=org.onap.policy.apex.domains.decisionmaker source=DCAE target=apex
result: SUCCESS

/root> event parameter create name=MakeDecisionEvent parName=mode schemaName=SimpleStringType
result: SUCCESS

/root> 
/root> event create name=DecisionEvent nameSpace=org.onap.policy.apex.domains.decisionmaker source=DCAE target=apex
result: SUCCESS

/root> event parameter create name=DecisionEvent parName=decision schemaName=SimpleStringType
result: SUCCESS

/root> 
/root> task create name=AnswerInitTask
result: SUCCESS

/root> task inputfield create name=AnswerInitTask fieldName=a0 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=AnswerInitTask fieldName=a1 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=AnswerInitTask fieldName=a2 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=AnswerInitTask fieldName=a3 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=AnswerInitTask fieldName=a4 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=AnswerInitTask fieldName=a5 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task inputfield create name=AnswerInitTask fieldName=a6 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=AnswerInitTask fieldName=a0 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=AnswerInitTask fieldName=a1 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=AnswerInitTask fieldName=a2 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=AnswerInitTask fieldName=a3 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=AnswerInitTask fieldName=a4 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=AnswerInitTask fieldName=a5 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> task outputfield create name=AnswerInitTask fieldName=a6 schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=AnswerInitTask albumName=AnswerAlbum
result: SUCCESS

/root> task contextref create name=AnswerInitTask albumName=LastAnswerAlbum
result: SUCCESS

/root> 
/root> task logic create name=AnswerInitTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var answerAlbum = executor.getContextAlbum("AnswerAlbum");

answerAlbum.put("a0", executor.inFields.get("a0"));
answerAlbum.put("a1", executor.inFields.get("a1"));
answerAlbum.put("a2", executor.inFields.get("a2"));
answerAlbum.put("a3", executor.inFields.get("a3"));
answerAlbum.put("a4", executor.inFields.get("a4"));
answerAlbum.put("a5", executor.inFields.get("a5"));
answerAlbum.put("a6", executor.inFields.get("a6"));

var lastAnswerAlbum = executor.getContextAlbum("LastAnswerAlbum");
lastAnswerAlbum.put("lastAnswer", answerAlbum.size() - 1);

executor.outFields.put("a0", answerAlbum.get("a0"));
executor.outFields.put("a1", answerAlbum.get("a1"));
executor.outFields.put("a2", answerAlbum.get("a2"));
executor.outFields.put("a3", answerAlbum.get("a3"));
executor.outFields.put("a4", answerAlbum.get("a4"));
executor.outFields.put("a5", answerAlbum.get("a5"));
executor.outFields.put("a6", answerAlbum.get("a6"));

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=RandomAnswerTask
result: SUCCESS

/root> 
/root> task inputfield create name=RandomAnswerTask fieldName=mode schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=RandomAnswerTask fieldName=decision schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=RandomAnswerTask albumName=AnswerAlbum
result: SUCCESS

/root> 
/root> task logic create name=RandomAnswerTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var size = executor.getContextAlbum("AnswerAlbum").size();

var selection = Math.floor(Math.random() * size);

var selectionA = "a" + selection;

executor.logger.info(size);
executor.logger.info(selectionA);

executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(selectionA));

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=PessimisticAnswerTask
result: SUCCESS

/root> 
/root> task inputfield create name=PessimisticAnswerTask fieldName=mode schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=PessimisticAnswerTask fieldName=decision schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=PessimisticAnswerTask albumName=AnswerAlbum
result: SUCCESS

/root> 
/root> task logic create name=PessimisticAnswerTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var size = executor.getContextAlbum("AnswerAlbum").size();

var selection = Math.floor(Math.random() * size / 2);

var selectionA = "a" + selection;

executor.logger.info(size);
executor.logger.info(selectionA);

executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(selectionA));

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=OptimisticAnswerTask
result: SUCCESS

/root> 
/root> task inputfield create name=OptimisticAnswerTask fieldName=mode schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=OptimisticAnswerTask fieldName=decision schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=OptimisticAnswerTask albumName=AnswerAlbum
result: SUCCESS

/root> 
/root> task logic create name=OptimisticAnswerTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var size = executor.getContextAlbum("AnswerAlbum").size();

var selection = size - Math.floor(Math.random() * size / 2) - 1;

var selectionA = "a" + selection;

executor.logger.info(size);
executor.logger.info(selectionA);

executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(selectionA));

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> task create name=DitheringAnswerTask
result: SUCCESS

/root> 
/root> task inputfield create name=DitheringAnswerTask fieldName=mode schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=DitheringAnswerTask fieldName=decision schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=DitheringAnswerTask albumName=AnswerAlbum
result: SUCCESS

/root> 
/root> task logic create name=DitheringAnswerTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var size = executor.getContextAlbum("AnswerAlbum").size();

var selection = 2 + Math.floor(Math.random() * 3);

var selectionA = "a" + selection;

executor.logger.info(size);
executor.logger.info(selectionA);

executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(selectionA));

executor.logger.info(executor.outFields);

true;


LE
result: SUCCESS

/root> 
/root> task create name=RoundRobinAnswerTask
result: SUCCESS

/root> 
/root> task inputfield create name=RoundRobinAnswerTask fieldName=mode schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task outputfield create name=RoundRobinAnswerTask fieldName=decision schemaName=SimpleStringType
result: SUCCESS
inputFields and outputFields are deprecated from Task definition and will be removed. Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition

/root> 
/root> task contextref create name=RoundRobinAnswerTask albumName=AnswerAlbum
result: SUCCESS

/root> task contextref create name=RoundRobinAnswerTask albumName=LastAnswerAlbum
result: SUCCESS

/root> 
/root> task logic create name=RoundRobinAnswerTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

var size = executor.getContextAlbum("AnswerAlbum").size();
var lastAnswer = executor.getContextAlbum("LastAnswerAlbum").get("lastAnswer");

executor.logger.info(size);
executor.logger.info(lastAnswer);

var answer = ++lastAnswer;
if (answer >= size) {
    answer = 0;
}

executor.getContextAlbum("LastAnswerAlbum").put("lastAnswer", answer)

var selectionA = "a" + answer;

executor.logger.info(selectionA);

executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(selectionA));

executor.logger.info(executor.outFields);

true;

LE
result: SUCCESS

/root> 
/root> policy create name=AnswerInitPolicy template=freestyle firstState=AnswerInitState
result: SUCCESS

/root> 
/root> policy state create name=AnswerInitPolicy stateName=AnswerInitState triggerName=AnswerEvent defaultTaskName=AnswerInitTask
result: SUCCESS

/root> policy state output create name=AnswerInitPolicy stateName=AnswerInitState outputName=AnswerInitOutput eventName=AnswerEvent
result: SUCCESS

/root> policy state taskref create name=AnswerInitPolicy stateName=AnswerInitState taskName=AnswerInitTask outputType=DIRECT outputName=AnswerInitOutput
result: SUCCESS

/root> 
/root> policy create name=DecisionMakerPolicy template=freestyle firstState=MakeDecisionState
result: SUCCESS

/root> 
/root> policy state create name=DecisionMakerPolicy stateName=MakeDecisionState triggerName=MakeDecisionEvent defaultTaskName=RandomAnswerTask
result: SUCCESS

/root> policy state output create name=DecisionMakerPolicy stateName=MakeDecisionState outputName=DecisionFinalOutput eventName=DecisionEvent
result: SUCCESS

/root> policy state taskref create name=DecisionMakerPolicy stateName=MakeDecisionState taskName=RandomAnswerTask outputType=DIRECT outputName=DecisionFinalOutput
result: SUCCESS

/root> policy state taskref create name=DecisionMakerPolicy stateName=MakeDecisionState taskName=PessimisticAnswerTask outputType=DIRECT outputName=DecisionFinalOutput
result: SUCCESS

/root> policy state taskref create name=DecisionMakerPolicy stateName=MakeDecisionState taskName=OptimisticAnswerTask outputType=DIRECT outputName=DecisionFinalOutput
result: SUCCESS

/root> policy state taskref create name=DecisionMakerPolicy stateName=MakeDecisionState taskName=DitheringAnswerTask outputType=DIRECT outputName=DecisionFinalOutput
result: SUCCESS

/root> policy state taskref create name=DecisionMakerPolicy stateName=MakeDecisionState taskName=RoundRobinAnswerTask outputType=DIRECT outputName=DecisionFinalOutput
result: SUCCESS

/root> 
/root> policy state selecttasklogic create name=DecisionMakerPolicy stateName=MakeDecisionState logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);

if (executor.inFields.get("mode").equals("random")) {
    executor.subject.getTaskKey("RandomAnswerTask").copyTo(executor.selectedTask);
}
else if (executor.inFields.get("mode").equals("pessimistic")) {
    executor.subject.getTaskKey("PessimisticAnswerTask").copyTo(executor.selectedTask);
}
else if (executor.inFields.get("mode").equals("optimistic")) {
    executor.subject.getTaskKey("OptimisticAnswerTask").copyTo(executor.selectedTask);
}
else if (executor.inFields.get("mode").equals("dithering")) {
    executor.subject.getTaskKey("DitheringAnswerTask").copyTo(executor.selectedTask);
}
else if (executor.inFields.get("mode").equals("roundrobin")) {
    executor.subject.getTaskKey("RoundRobinAnswerTask").copyTo(executor.selectedTask);
}

executor.logger.info("Answer Selected Task:" + executor.selectedTask);

true;

LE
result: SUCCESS

/root> 
/root> validate
result: SUCCESS
{
  "name": "DecisionMakerPolicyModel",
  "version": "0.0.1"
}
***validation of model successful***

/root> 
/root> 