summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--feature-controller-logging/src/main/feature/install/disable10
-rw-r--r--feature-controller-logging/src/main/feature/install/enable10
-rw-r--r--feature-distributed-locking/src/main/feature/install/disable10
-rw-r--r--feature-distributed-locking/src/main/feature/install/enable10
-rw-r--r--feature-eelf/src/main/feature/install/disable14
-rw-r--r--feature-eelf/src/main/feature/install/enable14
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java6
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java60
-rw-r--r--feature-lifecycle/src/test/resources/lifecycle.kmodule8
-rw-r--r--feature-lifecycle/src/test/resources/schemas/onap.policies.typeA-1.0.0.schema.json106
-rw-r--r--feature-lifecycle/src/test/resources/tosca-policy-other-unvalidated.json (renamed from feature-lifecycle/src/test/resources/tosca-policy-other.json)6
-rw-r--r--feature-lifecycle/src/test/resources/tosca-policy-other-validated.json22
-rw-r--r--feature-lifecycle/src/test/resources/tosca-policy-other-validation-error.json21
-rwxr-xr-xfeature-mdc-filters/src/main/feature/install/disable10
-rwxr-xr-xfeature-mdc-filters/src/main/feature/install/enable10
-rw-r--r--packages/base/src/files/bin/configure-maven6
-rw-r--r--packages/base/src/files/bin/monitor180
-rw-r--r--packages/base/src/files/bin/policy39
-rwxr-xr-xpackages/base/src/files/etc/cron.d/monitor.cron21
-rw-r--r--packages/base/src/files/etc/profile.d/env.sh10
-rw-r--r--packages/docker/src/main/docker/Dockerfile4
-rw-r--r--packages/docker/src/main/docker/pdpd-entrypoint.sh70
-rw-r--r--policy-management/src/main/server-gen/bin/add-secured-participant156
-rw-r--r--policy-management/src/main/server-gen/bin/create-api-key76
-rw-r--r--policy-management/src/main/server-gen/bin/create-secured-topic158
-rw-r--r--policy-management/src/main/server-gen/bin/db-migrator849
-rw-r--r--policy-management/src/main/server-gen/bin/deploy-artifact138
-rw-r--r--policy-management/src/main/server-gen/bin/features1783
-rw-r--r--policy-management/src/main/server-gen/bin/pdpd-configuration262
-rw-r--r--policy-management/src/main/server-gen/bin/policy-management-controller101
-rw-r--r--policy-management/src/main/server-gen/bin/rest-add-controller22
-rw-r--r--policy-management/src/main/server-gen/bin/rest-delete-controller6
-rw-r--r--policy-management/src/main/server-gen/bin/telemetry4
33 files changed, 2165 insertions, 2037 deletions
diff --git a/feature-controller-logging/src/main/feature/install/disable b/feature-controller-logging/src/main/feature/install/disable
index 698b6b3d..8233ec61 100644
--- a/feature-controller-logging/src/main/feature/install/disable
+++ b/feature-controller-logging/src/main/feature/install/disable
@@ -1,16 +1,16 @@
-#!/bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# feature-controller-logging
# ================================================================================
-# Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -23,4 +23,4 @@ for mainConfig in ${configDir}/logback.xml ${configDir}/logback-eelf.xml; do
if [ -e "${mainConfig}" ]; then
sed -i --follow-symlinks "/\<include.*logback\-include\-.*\.xml\>/d" "${mainConfig}"
fi
-done \ No newline at end of file
+done
diff --git a/feature-controller-logging/src/main/feature/install/enable b/feature-controller-logging/src/main/feature/install/enable
index 170598b3..d74bed8a 100644
--- a/feature-controller-logging/src/main/feature/install/enable
+++ b/feature-controller-logging/src/main/feature/install/enable
@@ -1,16 +1,16 @@
-#!/bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# feature-controller-logging
# ================================================================================
-# Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -26,4 +26,4 @@ for includedConfig in $(ls "${configDir}" | grep "logback-include-.*.xml"); do
sed -i --follow-symlinks "/\<configuration.*\> /a\ ${include}" "${mainConfig}"
fi
done
-done \ No newline at end of file
+done
diff --git a/feature-distributed-locking/src/main/feature/install/disable b/feature-distributed-locking/src/main/feature/install/disable
index ef05dbdc..c1b0fbc2 100644
--- a/feature-distributed-locking/src/main/feature/install/disable
+++ b/feature-distributed-locking/src/main/feature/install/disable
@@ -1,16 +1,16 @@
-#! /bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -18,7 +18,7 @@
# limitations under the License.
# ============LICENSE_END=========================================================
-if [[ "${DEBUG}" == "y" ]]; then
+if [ "${DEBUG}" = "y" ]; then
set -x
fi
diff --git a/feature-distributed-locking/src/main/feature/install/enable b/feature-distributed-locking/src/main/feature/install/enable
index 083433b6..5b8d1cb4 100644
--- a/feature-distributed-locking/src/main/feature/install/enable
+++ b/feature-distributed-locking/src/main/feature/install/enable
@@ -1,16 +1,16 @@
-#! /bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -18,7 +18,7 @@
# limitations under the License.
# ============LICENSE_END=========================================================
-if [[ "${DEBUG}" == "y" ]]; then
+if [ "${DEBUG}" = "y" ]; then
set -x
fi
diff --git a/feature-eelf/src/main/feature/install/disable b/feature-eelf/src/main/feature/install/disable
index 1eeb090e..5f3d178c 100644
--- a/feature-eelf/src/main/feature/install/disable
+++ b/feature-eelf/src/main/feature/install/disable
@@ -1,17 +1,17 @@
-#! /bin/bash
+#!/usr/bin/env ash
###
# ============LICENSE_START=======================================================
# ONAP POLICY
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -20,14 +20,14 @@
# ============LICENSE_END=========================================================
##
-if [[ "${DEBUG}" == "y" ]]; then
+if [ "${DEBUG}" = "y" ]; then
set -x
fi
SYSTEM_PROPS="${POLICY_HOME}"/config/system.properties
-if [[ -f ${SYSTEM_PROPS} && -r ${SYSTEM_PROPS} ]]; then
+if [ -f "${SYSTEM_PROPS}" ] && [ -r "${SYSTEM_PROPS}" ]; then
if grep -q "^logback.configurationFile=.*$" "${SYSTEM_PROPS}"; then
sed -i -e "s|^logback.configurationFile=.*$|logback.configurationFile=config/logback.xml|" "${SYSTEM_PROPS}"
fi
-fi \ No newline at end of file
+fi
diff --git a/feature-eelf/src/main/feature/install/enable b/feature-eelf/src/main/feature/install/enable
index 55a2b99a..b80e21bc 100644
--- a/feature-eelf/src/main/feature/install/enable
+++ b/feature-eelf/src/main/feature/install/enable
@@ -1,17 +1,17 @@
-#! /bin/bash
+#!/usr/bin/env ash
###
# ============LICENSE_START=======================================================
# ONAP POLICY
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -20,16 +20,16 @@
# ============LICENSE_END=========================================================
##
-if [[ "${DEBUG}" == "y" ]]; then
+if [ "${DEBUG}" = "y" ]; then
set -x
fi
SYSTEM_PROPS="${POLICY_HOME}"/config/system.properties
-if [[ -f ${SYSTEM_PROPS} && -r ${SYSTEM_PROPS} ]]; then
+if [ -f "${SYSTEM_PROPS}" ] && [ -r "${SYSTEM_PROPS}" ]; then
if grep -q "^logback.configurationFile=.*$" "${SYSTEM_PROPS}"; then
sed -i -e "s|^logback.configurationFile=.*$|logback.configurationFile=config/logback-eelf.xml|" "${SYSTEM_PROPS}"
else
echo "logback.configurationFile=config/logback-eelf.xml" >> "${SYSTEM_PROPS}"
fi
-fi \ No newline at end of file
+fi
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
index 957ecfa6..b430533d 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
@@ -286,8 +286,10 @@ public class RestLifecycleManager {
List<ToscaPolicy> policies =
LifecycleFeature.fsm.getPoliciesMap().values().stream().collect(Collectors.toList());
policies.add(toscaPolicy);
- return Response.status(Response.Status.OK)
- .entity(LifecycleFeature.fsm.update(getPolicyUpdate(policies)))
+
+ boolean updateResult = LifecycleFeature.fsm.update(getPolicyUpdate(policies));
+ return Response.status((updateResult ? Response.Status.OK : Response.Status.NOT_ACCEPTABLE))
+ .entity(updateResult)
.build();
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
index 0751eb54..3a04c313 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
@@ -18,6 +18,7 @@
package org.onap.policy.drools.server.restful;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -76,9 +77,17 @@ public class RestLifecycleManagerTest {
private static final String EXAMPLE_NATIVE_ARTIFACT_POLICY_JSON =
"src/test/resources/tosca-policy-native-artifact-example.json";
- private static final String EXAMPLE_OTHER_POLICY_NAME = "other";
- private static final String EXAMPLE_OTHER_POLICY_JSON =
- "src/test/resources/tosca-policy-other.json";
+ private static final String EXAMPLE_OTHER_UNVAL_POLICY_NAME = "other-unvalidated";
+ private static final String EXAMPLE_OTHER_UNVAL_POLICY_JSON =
+ "src/test/resources/tosca-policy-other-unvalidated.json";
+
+ private static final String EXAMPLE_OTHER_VAL_POLICY_NAME = "other-validated";
+ private static final String EXAMPLE_OTHER_VAL_POLICY_JSON =
+ "src/test/resources/tosca-policy-other-validated.json";
+
+ private static final String EXAMPLE_OTHER_VAL_ERROR_POLICY_NAME = "other-validation-error";
+ private static final String EXAMPLE_OTHER_VAL_ERROR_POLICY_JSON =
+ "src/test/resources/tosca-policy-other-validation-error.json";
private static final String OP_POLICY_NAME_VCPE = "operational.restart";
private static final String VCPE_OPERATIONAL_DROOLS_POLICY_JSON =
@@ -216,11 +225,12 @@ public class RestLifecycleManagerTest {
/* verify new supported operational policy types */
- resourceLists("policyTypes", 4);
+ resourceLists("policyTypes", 5);
get("policyTypes/onap.policies.native.drools.Artifact/1.0.0", Status.OK.getStatusCode());
get("policyTypes/onap.policies.native.drools.Controller/1.0.0", Status.OK.getStatusCode());
get("policyTypes/onap.policies.controlloop.operational.common.Drools/1.0.0", Status.OK.getStatusCode());
get("policyTypes/onap.policies.type1.type2/1.0.0", Status.OK.getStatusCode());
+ get("policyTypes/onap.policies.typeA/1.0.0", Status.OK.getStatusCode());
/* verify controller and artifact policies */
@@ -237,10 +247,24 @@ public class RestLifecycleManagerTest {
}
testNotNativePolicy(opPolicy);
- /* add tosca "other" of policy type "other" with no attached type schema */
+ /* add tosca policy "other-unvalidated" of policy type "type1.type2" with no attached type schema */
+
+ testNotNativePolicy(getPolicyFromFile(EXAMPLE_OTHER_UNVAL_POLICY_JSON, EXAMPLE_OTHER_UNVAL_POLICY_NAME));
+
+ /* add tosca policy "other-validated" of policy type "typeA" with an attached type schema */
+
+ testNotNativePolicy(getPolicyFromFile(EXAMPLE_OTHER_VAL_POLICY_JSON, EXAMPLE_OTHER_VAL_POLICY_NAME));
- ToscaPolicy otherPolicy = getPolicyFromFile(EXAMPLE_OTHER_POLICY_JSON, EXAMPLE_OTHER_POLICY_NAME);
- testNotNativePolicy(otherPolicy);
+ /* try to add invalid tosca policy "other-validation-error" of policy type "typeA" */
+
+ ToscaPolicy toscaPolicyValError =
+ getPolicyFromFile(EXAMPLE_OTHER_VAL_ERROR_POLICY_JSON, EXAMPLE_OTHER_VAL_ERROR_POLICY_NAME);
+ assertThat(
+ listPost("policies/operations/validation", toString(toscaPolicyValError),
+ Status.NOT_ACCEPTABLE.getStatusCode())).isNotEmpty();
+
+ booleanPost("policies", toString(toscaPolicyValError),
+ Status.NOT_ACCEPTABLE.getStatusCode(), Boolean.FALSE);
/* individual deploy/undeploy operations */
@@ -278,6 +302,7 @@ public class RestLifecycleManagerTest {
get("policyTypes/onap.policies.native.drools.Controller/1.0.0", Status.OK.getStatusCode());
get("policyTypes/onap.policies.controlloop.operational.common.Drools/1.0.0", Status.NOT_FOUND.getStatusCode());
get("policyTypes/onap.policies.type1.type2/1.0.0", Status.NOT_FOUND.getStatusCode());
+ get("policyTypes/onap.policies.typeA/1.0.0", Status.NOT_FOUND.getStatusCode());
resourceLists("policies", 1);
get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.NOT_FOUND.getStatusCode());
@@ -293,6 +318,7 @@ public class RestLifecycleManagerTest {
get("policyTypes/onap.policies.native.drools.Controller/1.0.0", Status.OK.getStatusCode());
get("policyTypes/onap.policies.controlloop.operational.common.Drools/1.0.0", Status.NOT_FOUND.getStatusCode());
get("policyTypes/onap.policies.type1.type2/1.0.0", Status.NOT_FOUND.getStatusCode());
+ get("policyTypes/onap.policies.typeA/1.0.0", Status.NOT_FOUND.getStatusCode());
resourceLists("policies", 0);
get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.NOT_FOUND.getStatusCode());
@@ -301,17 +327,17 @@ public class RestLifecycleManagerTest {
assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle"));
opPolicy.getMetadata().remove("policy-id");
- assertFalse(
+ assertThat(
listPost("policies/operations/validation", toString(opPolicy),
- Status.NOT_ACCEPTABLE.getStatusCode()).isEmpty());
+ Status.NOT_ACCEPTABLE.getStatusCode())).isNotEmpty();
}
- private void testNotNativePolicy(ToscaPolicy opPolicy) throws CoderException {
- assertTrue(
- listPost("policies/operations/validation", toString(opPolicy),
- Status.OK.getStatusCode()).isEmpty());
+ private void testNotNativePolicy(ToscaPolicy toscaPolicy) throws CoderException {
+ assertThat(
+ listPost("policies/operations/validation", toString(toscaPolicy),
+ Status.OK.getStatusCode())).isEmpty();
- booleanPost("policies", toString(opPolicy), Status.OK.getStatusCode(), Boolean.TRUE);
+ booleanPost("policies", toString(toscaPolicy), Status.OK.getStatusCode(), Boolean.TRUE);
assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").isAlive());
assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained());
assertEquals(1,
@@ -319,18 +345,18 @@ public class RestLifecycleManagerTest {
.getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size());
resourceLists("policies", 3);
- get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.OK.getStatusCode());
+ get("policies/" + toscaPolicy.getName() + "/" + toscaPolicy.getVersion(), Status.OK.getStatusCode());
get("policies/example.controller/1.0.0", Status.OK.getStatusCode());
get("policies/example.artifact/1.0.0", Status.OK.getStatusCode());
- booleanDelete("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(),
+ booleanDelete("policies/" + toscaPolicy.getName() + "/" + toscaPolicy.getVersion(),
Status.OK.getStatusCode(), Boolean.TRUE);
assertEquals(0,
PolicyControllerConstants
.getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size());
resourceLists("policies", 2);
- get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.NOT_FOUND.getStatusCode());
+ get("policies/" + toscaPolicy.getName() + "/" + toscaPolicy.getVersion(), Status.NOT_FOUND.getStatusCode());
get("policies/example.controller/1.0.0", Status.OK.getStatusCode());
get("policies/example.artifact/1.0.0", Status.OK.getStatusCode());
}
diff --git a/feature-lifecycle/src/test/resources/lifecycle.kmodule b/feature-lifecycle/src/test/resources/lifecycle.kmodule
index 529730bd..56ca0923 100644
--- a/feature-lifecycle/src/test/resources/lifecycle.kmodule
+++ b/feature-lifecycle/src/test/resources/lifecycle.kmodule
@@ -3,7 +3,7 @@
============LICENSE_START=======================================================
feature-controller-logging
================================================================================
- Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -20,8 +20,10 @@
-->
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
- <kbase name="onap.policies.controlloop.operational.common.Drools" default="false" equalsBehavior="equality"/>
+ <kbase name="onap.policies.typeA" default="false" equalsBehavior="equality"/>
+ <kbase name="onap.policies.controlloop.operational.common.Drools"
+ includes="onap.policies.typeA" default="false" equalsBehavior="equality"/>
<kbase name="onap.policies.type1.type2" includes="onap.policies.controlloop.operational.common.Drools">
<ksession name="junits" />
</kbase>
-</kmodule>
+</kmodule> \ No newline at end of file
diff --git a/feature-lifecycle/src/test/resources/schemas/onap.policies.typeA-1.0.0.schema.json b/feature-lifecycle/src/test/resources/schemas/onap.policies.typeA-1.0.0.schema.json
new file mode 100644
index 00000000..91712460
--- /dev/null
+++ b/feature-lifecycle/src/test/resources/schemas/onap.policies.typeA-1.0.0.schema.json
@@ -0,0 +1,106 @@
+{
+ "definitions": {},
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "$id": "http://www.onap.org/policy/models/schemas/onap.policies.typeA.schema.json",
+ "type": "object",
+ "title": "The Root Schema",
+ "required": [
+ "type",
+ "type_version",
+ "version",
+ "metadata",
+ "properties"
+ ],
+ "properties": {
+ "type": {
+ "$id": "#/properties/type",
+ "type": "string",
+ "title": "Policy Type",
+ "default": "onap.policies.typeA",
+ "examples": [
+ "onap.policies.typeA"
+ ],
+ "pattern": "^(.+)$"
+ },
+ "type_version": {
+ "$id": "#/properties/type_version",
+ "type": "string",
+ "title": "Policy Type Version",
+ "default": "1.0.0",
+ "examples": [
+ "1.0.0"
+ ],
+ "pattern": "^(.+)$"
+ },
+ "name": {
+ "$id": "#/properties/name",
+ "type": "string",
+ "title": "Policy Name",
+ "default": "",
+ "examples": [
+ "example"
+ ],
+ "pattern": "^(.*)$"
+ },
+ "version": {
+ "$id": "#/properties/version",
+ "type": "string",
+ "title": "Policy Version",
+ "default": "1.0.0",
+ "examples": [
+ "1.0.0"
+ ],
+ "pattern": "^(.+)$"
+ },
+ "metadata": {
+ "$id": "#/properties/metadata",
+ "type": "object",
+ "title": "Metadata",
+ "required": [
+ "policy-id"
+ ],
+ "properties": {
+ "policy-id": {
+ "$id": "#/properties/metadata/properties/policy-id",
+ "type": "string",
+ "title": "Policy ID",
+ "examples": [
+ "operational.restart"
+ ],
+ "pattern": "^(.+)$"
+ }
+ }
+ },
+ "properties": {
+ "$id": "#/properties/properties",
+ "type": "object",
+ "title": "Properties",
+ "required": [
+ "fieldA",
+ "fieldB"
+ ],
+ "properties": {
+ "fieldA": {
+ "$id": "#/properties/properties/properties/fieldA",
+ "type": "string",
+ "title": "Field A",
+ "examples": [
+ "FieldA"
+ ],
+ "pattern": "^(.+)$"
+ },
+ "fieldB": {
+ "$id": "#/properties/properties/properties/fieldB",
+ "type": "integer",
+ "title": "Timeout in seconds",
+ "minimum": 1,
+ "maximum": 5,
+ "default": 1,
+ "examples": [
+ 3
+ ]
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/feature-lifecycle/src/test/resources/tosca-policy-other.json b/feature-lifecycle/src/test/resources/tosca-policy-other-unvalidated.json
index 33aed19b..64a59b2a 100644
--- a/feature-lifecycle/src/test/resources/tosca-policy-other.json
+++ b/feature-lifecycle/src/test/resources/tosca-policy-other-unvalidated.json
@@ -3,13 +3,13 @@
"topology_template": {
"policies": [
{
- "other": {
+ "other-unvalidated": {
"type": "onap.policies.type1.type2",
"type_version": "1.0.0",
- "name": "other",
+ "name": "other-unvalidated",
"version": "1.0.0",
"metadata": {
- "policy-id": "other"
+ "policy-id": "other-unvalidated"
},
"properties": {
"field1": "abc",
diff --git a/feature-lifecycle/src/test/resources/tosca-policy-other-validated.json b/feature-lifecycle/src/test/resources/tosca-policy-other-validated.json
new file mode 100644
index 00000000..e79435c6
--- /dev/null
+++ b/feature-lifecycle/src/test/resources/tosca-policy-other-validated.json
@@ -0,0 +1,22 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "topology_template": {
+ "policies": [
+ {
+ "other-validated": {
+ "type": "onap.policies.typeA",
+ "type_version": "1.0.0",
+ "name": "other-validated",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "other-validated"
+ },
+ "properties": {
+ "fieldA": "abc",
+ "fieldB": 2
+ }
+ }
+ }
+ ]
+ }
+}
diff --git a/feature-lifecycle/src/test/resources/tosca-policy-other-validation-error.json b/feature-lifecycle/src/test/resources/tosca-policy-other-validation-error.json
new file mode 100644
index 00000000..f7af04bb
--- /dev/null
+++ b/feature-lifecycle/src/test/resources/tosca-policy-other-validation-error.json
@@ -0,0 +1,21 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "topology_template": {
+ "policies": [
+ {
+ "other-validation-error": {
+ "type": "onap.policies.typeA",
+ "type_version": "1.0.0",
+ "name": "other-validation-error",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "other-validation-error"
+ },
+ "properties": {
+ "fieldA": "abc"
+ }
+ }
+ }
+ ]
+ }
+}
diff --git a/feature-mdc-filters/src/main/feature/install/disable b/feature-mdc-filters/src/main/feature/install/disable
index 25d57374..dda7e695 100755
--- a/feature-mdc-filters/src/main/feature/install/disable
+++ b/feature-mdc-filters/src/main/feature/install/disable
@@ -1,17 +1,17 @@
-#!/bin/bash
+#!/usr/bin/env ash
###
# ============LICENSE_START=======================================================
# feature-mdc-filters
# ================================================================================
-# Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -20,7 +20,7 @@
# ============LICENSE_END=========================================================
##
-if [[ "${DEBUG}" == "y" ]]; then
+if [ "${DEBUG}" = "y" ]; then
set -x
fi
diff --git a/feature-mdc-filters/src/main/feature/install/enable b/feature-mdc-filters/src/main/feature/install/enable
index 57c7cc4a..63f907e8 100755
--- a/feature-mdc-filters/src/main/feature/install/enable
+++ b/feature-mdc-filters/src/main/feature/install/enable
@@ -1,17 +1,17 @@
-#!/bin/bash
+#!/usr/bin/env ash
###
# ============LICENSE_START=======================================================
# feature-mdc-filters
# ================================================================================
-# Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -20,7 +20,7 @@
# ============LICENSE_END=========================================================
##
-if [[ "${DEBUG}" == "y" ]]; then
+if [ "${DEBUG}" = "y" ]; then
set -x
fi
diff --git a/packages/base/src/files/bin/configure-maven b/packages/base/src/files/bin/configure-maven
index 7da5f6a4..34d6de70 100644
--- a/packages/base/src/files/bin/configure-maven
+++ b/packages/base/src/files/bin/configure-maven
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -20,14 +20,14 @@
source ${POLICY_HOME}/etc/profile.d/env.sh
-if [[ ${DEBUG} == y ]]; then
+if [ "${DEBUG}" = "y" ]; then
set -x
fi
HOME_M2="${HOME}"/.m2
mkdir -p "${HOME_M2}" 2> /dev/null
-if [[ -z "${SNAPSHOT_REPOSITORY_URL}" && -z "${RELEASE_REPOSITORY_URL}" ]]; then
+if [ -z "${SNAPSHOT_REPOSITORY_URL}" ] && [ -z "${RELEASE_REPOSITORY_URL}" ]; then
ln -s -f "${POLICY_HOME}"/etc/m2/standalone-settings.xml "${HOME_M2}"/settings.xml
else
ln -s -f "${POLICY_HOME}"/etc/m2/settings.xml "${HOME_M2}"/settings.xml
diff --git a/packages/base/src/files/bin/monitor b/packages/base/src/files/bin/monitor
index 6d40f7e2..864582f1 100644
--- a/packages/base/src/files/bin/monitor
+++ b/packages/base/src/files/bin/monitor
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -21,122 +21,118 @@
source ${POLICY_HOME}/etc/profile.d/env.sh
function usage() {
- echo -n "syntax: $(basename $0) "
- echo "[--debug]"
+ echo -n "syntax: $(basename $0) "
+ echo "[--debug]"
}
function log() {
- echo "$(date +"%Y-%m-%d_%H-%M-%S") $1" >> ${POLICY_HOME}/logs/monitor.log
+ echo "$(date +"%Y-%m-%d_%H-%M-%S") $1" >> ${POLICY_HOME}/logs/monitor.log
}
function monitor() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- CONTROLLER=$1
- STATUS=$2
-
- if [[ -z ${CONTROLLER} ]]; then
- log "WARNING: invalid invocation: no component provided"
- return
- fi
-
- if [[ -z ${STATUS} ]]; then
- log "WARNING: invalid invocation: no on/off/uninstalled switch provided for ${CONTROLLER}"
- return
- fi
-
- if [[ "${STATUS}" == "off" ]]; then
- off ${CONTROLLER}
- else
- if [[ "${STATUS}" == "on" ]]; then
- on ${CONTROLLER}
- fi
- fi
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- monitor --"
+ set -x
+ fi
+
+ CONTROLLER=$1
+ STATUS=$2
+
+ if [ -z "${CONTROLLER}" ]; then
+ log "WARNING: invalid invocation: no component provided"
+ return
+ fi
+
+ if [ -z "${STATUS}" ]; then
+ log "WARNING: invalid invocation: no on/off/uninstalled switch provided for ${CONTROLLER}"
+ return
+ fi
+
+ if [ "${STATUS}" = "off" ]; then
+ off ${CONTROLLER}
+ else
+ if [ "${STATUS}" = "on" ]; then
+ on ${CONTROLLER}
+ fi
+ fi
}
function on() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- CONTROLLER=$1
-
- ${POLICY_HOME}/bin/${CONTROLLER} status
- if [[ $? != 0 ]]; then
- log "starting ${CONTROLLER}"
-
- # need to make sure we don't pass the lock file descriptor
- ${POLICY_HOME}/bin/${CONTROLLER} umstart {cfg}>&-
- else
- log "OK: ${CONTROLLER} (UP)"
- fi
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- on --"
+ set -x
+ fi
+
+ CONTROLLER=$1
+
+ ${POLICY_HOME}/bin/${CONTROLLER} status
+ if [ $? -ne 0 ]; then
+ log "starting ${CONTROLLER}"
+
+ # need to make sure we don't pass the lock file descriptor
+ ${POLICY_HOME}/bin/${CONTROLLER} umstart 200>&-
+ else
+ log "OK: ${CONTROLLER} (UP)"
+ fi
}
function off() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- CONTROLLER=$1
-
- ${POLICY_HOME}/bin/${CONTROLLER} status
- if [[ $? != 0 ]]; then
- log "OK: ${CONTROLLER} (DOWN)"
-
- else
- log "stopping ${CONTROLLER}"
- ${POLICY_HOME}/bin/${CONTROLLER} umstop
- fi
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- off --"
+ set -x
+ fi
+
+ CONTROLLER=$1
+
+ ${POLICY_HOME}/bin/${CONTROLLER} status
+ if [ $? -ne 0 ]; then
+ log "OK: ${CONTROLLER} (DOWN)"
+
+ else
+ log "stopping ${CONTROLLER}"
+ ${POLICY_HOME}/bin/${CONTROLLER} umstop
+ fi
}
function process_config() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- CONF_FILE=${POLICY_HOME}/etc/monitor/monitor.cfg
- while read line || [ -n "${line}" ]; do
- if [[ -n ${line} ]] && [[ ${line} != *#* ]]; then
- controller=$(echo "${line}" | awk -F = '{print $1;}')
- status=$(echo "${line}" | awk -F = '{print $2;}')
- if [[ -n ${controller} ]] && [[ -n ${status} ]]; then
- monitor ${controller} ${status}
- fi
- fi
- done < "${CONF_FILE}"
- return 0
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- process_config --"
+ set -x
+ fi
+ local lines=$(grep "^[^#;]" ${CON_FILE} 2> /dev/null)
+ for line in ${lines} ; do
+ controller=$(echo "${line}" | awk -F = '{print $1;}')
+ status=$(echo "${line}" | awk -F = '{print $2;}')
+ if [ -n "${controller}" ] && [ -n "${status}" ]; then
+ monitor ${controller} ${status}
+ fi
+ done
+ return 0
}
log "Enter monitor"
DEBUG=n
until [[ -z "$1" ]]; do
- case $1 in
- -d|--debug|debug) DEBUG=y
- set -x
- ;;
- *) usage
- exit 1
- ;;
- esac
- shift
+ case $1 in
+ -d|--debug|debug) DEBUG=y
+ set -x
+ ;;
+ *) usage
+ exit 1
+ ;;
+ esac
+ shift
done
if pidof -o %PPID -x $(basename $0) > /dev/null 2>&1; then
- log "WARNING: $(basename $0) from the previous iteration still running. Exiting."
- exit 1
+ log "WARNING: $(basename $0) from the previous iteration still running. Exiting."
+ exit 1
fi
+CONF_FILE=${POLICY_HOME}/etc/monitor/monitor.cfg
. ${POLICY_HOME}/etc/profile.d/env.sh
-if flock ${cfg} ; then
- process_config
-fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
-
-
+if flock 200 ; then
+ process_config
+fi 200>>${CONF_FILE}.lock
diff --git a/packages/base/src/files/bin/policy b/packages/base/src/files/bin/policy
index 9bc294d8..3ba75f0d 100644
--- a/packages/base/src/files/bin/policy
+++ b/packages/base/src/files/bin/policy
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -25,8 +25,8 @@ function usage() {
}
function check_x_file() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- check_x_file --"
set -x
fi
@@ -39,8 +39,8 @@ function check_x_file() {
}
function policy_op() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- policy_op --"
set -x
fi
@@ -53,13 +53,13 @@ function policy_op() {
${BIN_SCRIPT} ${operation} >/tmp/out$$
echo " L [${controller}]: $(sed ':a;N;$!ba;s/\n/ /g' /tmp/out$$)"
else
- echo " L [${controller}]: -"
+ echo " L [${controller}]: -"
fi
}
function policy_status() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- policy_status --"
set -x
fi
@@ -67,14 +67,14 @@ function policy_status() {
policy_op "status"
NUM_CRONS=$(crontab -l 2>/dev/null | wc -l)
- echo " ${NUM_CRONS} cron jobs installed."
+ echo " ${NUM_CRONS} cron jobs installed."
echo
echo "[features]"
features status
local databases=$(ls -d "${POLICY_HOME}"/etc/db/migration/*/ 2>/dev/null)
- if [[ -n ${databases} ]]; then
+ if [ -n "${databases}" ]; then
echo "[migration]"
db-migrator -s ALL -o ok
fi
@@ -82,8 +82,8 @@ function policy_status() {
}
function policy_start() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- policy_start --"
set -x
fi
@@ -91,8 +91,8 @@ function policy_start() {
}
function policy_exec() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- policy_exec --"
set -x
fi
@@ -103,8 +103,8 @@ function policy_exec() {
}
function policy_stop() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- policy_stop --"
set -x
fi
@@ -119,15 +119,14 @@ function policy_stop() {
source ${POLICY_HOME}/etc/profile.d/env.sh
-if [[ ${DEBUG} == y ]]; then
+if [ "${DEBUG}" = "y" ]; then
echo "-- $0 $* --"
set -x
fi
BIN_SCRIPT="bin/policy-management-controller"
OPERATION=none
-
-until [[ -z "$1" ]]; do
+until [ -z "$1" ]; do
case $1 in
-d | --debug | debug)
DEBUG=y
@@ -166,7 +165,7 @@ halt) ;;
;;
esac
-if [[ -z ${POLICY_HOME} ]]; then
+if [ -z "${POLICY_HOME}" ]; then
echo "error: POLICY_HOME is unset."
exit 1
fi
diff --git a/packages/base/src/files/etc/cron.d/monitor.cron b/packages/base/src/files/etc/cron.d/monitor.cron
deleted file mode 100755
index 338c1d44..00000000
--- a/packages/base/src/files/etc/cron.d/monitor.cron
+++ /dev/null
@@ -1,21 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# ONAP
-# ================================================================================
-# Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
-# ================================================================================
-# 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.
-# ============LICENSE_END=========================================================
-###
-
-* * * * * bash -l -c '${POLICY_HOME}/bin/monitor >/dev/null 2>&1'
diff --git a/packages/base/src/files/etc/profile.d/env.sh b/packages/base/src/files/etc/profile.d/env.sh
index 9ffd026c..a1b9fa7d 100644
--- a/packages/base/src/files/etc/profile.d/env.sh
+++ b/packages/base/src/files/etc/profile.d/env.sh
@@ -1,16 +1,16 @@
-#!/bin/bash
+#!/bin/ash
###
# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -28,7 +28,7 @@
templateRegex='^\$\{\{POLICY_HOME}}$'
-if [[ -z "${POLICY_HOME}" ]]; then
+if [ -z "${POLICY_HOME}" ]; then
templatedPolicyHome='${{POLICY_HOME}}'
if [[ ! ${templatedPolicyHome} =~ ${templateRegex} ]]; then
POLICY_HOME=${templatedPolicyHome}
diff --git a/packages/docker/src/main/docker/Dockerfile b/packages/docker/src/main/docker/Dockerfile
index 31a17ec4..b7f2d62e 100644
--- a/packages/docker/src/main/docker/Dockerfile
+++ b/packages/docker/src/main/docker/Dockerfile
@@ -61,14 +61,14 @@ COPY --chown=policy:policy /maven/install-drools.zip pdpd-entrypoint.sh $POLICY_
WORKDIR $POLICY_INSTALL
USER policy:policy
-SHELL ["/bin/bash", "-c"]
+SHELL ["/bin/ash", "-c"]
RUN unzip -o install-drools.zip && \
rm install-drools.zip && \
chown -R policy:policy * && \
mkdir -p $POLICY_HOME/logs $POLICY_HOME/config $HOME/.m2 && \
tar -C $POLICY_HOME -xvf base-${BUILD_VERSION_DROOLS}.tar.gz --no-same-owner && \
unzip policy-management-${BUILD_VERSION_DROOLS}.zip -d $POLICY_HOME && \
- echo "source $POLICY_HOME/etc/profile.d/env.sh" >> "$HOME/.bashrc" && \
+ echo "source $POLICY_HOME/etc/profile.d/env.sh" >> "$HOME/.profile" && \
mv pdpd-entrypoint.sh $POLICY_HOME/bin/ && \
chmod 700 $POLICY_HOME/bin/* && \
chmod 600 $POLICY_HOME/config/* && \
diff --git a/packages/docker/src/main/docker/pdpd-entrypoint.sh b/packages/docker/src/main/docker/pdpd-entrypoint.sh
index fb98e86a..56b53e3e 100644
--- a/packages/docker/src/main/docker/pdpd-entrypoint.sh
+++ b/packages/docker/src/main/docker/pdpd-entrypoint.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env ash
# ########################################################################
# Copyright 2019-2020 AT&T Intellectual Property. All rights reserved
@@ -18,19 +18,19 @@
function maven {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- maven --"
set -x
fi
- if [[ -f "${POLICY_INSTALL_INIT}"/settings.xml ]]; then
+ if [ -f "${POLICY_INSTALL_INIT}"/settings.xml ]; then
if ! cmp -s "${POLICY_INSTALL_INIT}"/settings.xml "${POLICY_HOME}"/etc/m2/settings.xml; then
echo "overriding settings.xml"
cp -f "${POLICY_INSTALL_INIT}"/settings.xml "${POLICY_HOME}"/etc/m2
fi
fi
- if [[ -f "${POLICY_INSTALL_INIT}"/standalone-settings.xml ]]; then
+ if [ -f "${POLICY_INSTALL_INIT}"/standalone-settings.xml ]; then
if ! cmp -s "${POLICY_INSTALL_INIT}"/standalone-settings.xml "${POLICY_HOME}"/etc/m2/standalone-settings.xml; then
echo "overriding standalone-settings.xml"
cp -f "${POLICY_INSTALL_INIT}"/standalone-settings.xml "${POLICY_HOME}"/etc/m2
@@ -39,8 +39,8 @@ function maven {
}
function systemConfs {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- systemConfs --"
set -x
fi
@@ -61,8 +61,8 @@ function systemConfs {
}
function features {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- features --"
set -x
fi
@@ -79,8 +79,8 @@ function features {
}
function scripts {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- scripts --"
set -x
fi
@@ -99,26 +99,26 @@ function scripts {
}
function security {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- security --"
set -x
fi
- if [[ -f "${POLICY_INSTALL_INIT}"/policy-keystore ]]; then
+ if [ -f "${POLICY_INSTALL_INIT}"/policy-keystore ]; then
if ! cmp -s "${POLICY_INSTALL_INIT}"/policy-keystore "${POLICY_HOME}"/etc/ssl/policy-keystore; then
echo "overriding policy-keystore"
cp -f "${POLICY_INSTALL_INIT}"/policy-keystore "${POLICY_HOME}"/etc/ssl
fi
fi
- if [[ -f ${POLICY_INSTALL_INIT}/policy-truststore ]]; then
+ if [ -f "${POLICY_INSTALL_INIT}"/policy-truststore ]; then
if ! cmp -s "${POLICY_INSTALL_INIT}"/policy-truststore "${POLICY_HOME}"/etc/ssl/policy-truststore; then
echo "overriding policy-truststore"
cp -f "${POLICY_INSTALL_INIT}"/policy-truststore "${POLICY_HOME}"/etc/ssl
fi
fi
- if [[ -f "${POLICY_INSTALL_INIT}"/aaf-cadi.keyfile ]]; then
+ if [ -f "${POLICY_INSTALL_INIT}"/aaf-cadi.keyfile ]; then
if ! cmp -s "${POLICY_INSTALL_INIT}"/aaf-cadi.keyfile "${POLICY_HOME}"/config/aaf-cadi.keyfile; then
echo "overriding aaf-cadi.keyfile"
cp -f "${POLICY_INSTALL_INIT}"/aaf-cadi.keyfile "${POLICY_HOME}"/config/aaf-cadi.keyfile
@@ -127,8 +127,8 @@ function security {
}
function serverConfig {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- serverConfig --"
set -x
fi
@@ -145,24 +145,24 @@ function serverConfig {
}
function db {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- db --"
set -x
fi
- if [[ -z ${SQL_HOST} ]]; then
+ if [ -z "${SQL_HOST}" ]; then
return 0
fi
echo "Wating for ${SQL_HOST} ."
- timeout 120 bash -c 'until nc -vz "${SQL_HOST}" 3306; do echo -n "."; sleep 1; done'; echo $?
+ timeout 120 ash -c 'until nc -vz "${SQL_HOST}" 3306; do echo -n "."; sleep 1; done'; echo $?
"${POLICY_HOME}"/bin/db-migrator -s ALL -o upgrade
}
function inspect {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- inspect --"
set -x
fi
@@ -179,8 +179,8 @@ function inspect {
}
function reload {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- reload --"
set -x
fi
@@ -195,8 +195,8 @@ function reload {
}
function start {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- start --"
set -x
fi
@@ -205,8 +205,8 @@ function start {
}
function configure {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]]; then
+ echo "-- configure --"
set -x
fi
@@ -215,8 +215,8 @@ function configure {
}
function vmBoot {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- vmBoot --"
set -x
fi
@@ -227,8 +227,8 @@ function vmBoot {
}
function dockerBoot {
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- dockerBoot --"
set -x
fi
@@ -240,7 +240,7 @@ function dockerBoot {
policy exec
}
-if [[ ${DEBUG} == y ]]; then
+if [ "${DEBUG}" = "y" ]; then
echo "-- $0 $* --"
set -x
fi
diff --git a/policy-management/src/main/server-gen/bin/add-secured-participant b/policy-management/src/main/server-gen/bin/add-secured-participant
index d6843fee..4a776703 100644
--- a/policy-management/src/main/server-gen/bin/add-secured-participant
+++ b/policy-management/src/main/server-gen/bin/add-secured-participant
@@ -1,17 +1,17 @@
-#! /bin/bash
+#!/usr/bin/env ash
###
# ============LICENSE_START=======================================================
# policy-management
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -21,91 +21,91 @@
###
function usage() {
- echo -n "Usage: $(basename $0) "
- echo -n "[(-d|--debug)] "
- echo -n "(-h|--host) <bus-host> "
- echo -n "[(-p|--port) <bus-port>] "
- echo -n "(-k|--key) <api-key> "
- echo -n "(-s|--secret) <api-secret> "
- echo -n "(-P|--producer-key) <producer-key> "
- echo -n "(-C|--consumer-key) <consumer-key> "
- echo "(-t|--topic) <topic> "
+ echo -n "Usage: $(basename $0) "
+ echo -n "[(-d|--debug)] "
+ echo -n "(-h|--host) <bus-host> "
+ echo -n "[(-p|--port) <bus-port>] "
+ echo -n "(-k|--key) <api-key> "
+ echo -n "(-s|--secret) <api-secret> "
+ echo -n "(-P|--producer-key) <producer-key> "
+ echo -n "(-C|--consumer-key) <consumer-key> "
+ echo "(-t|--topic) <topic> "
}
BUS_PORT=3904
# command line options parsing
-until [[ -z "$1" ]]; do
- case $1 in
- -d|--debug) set -x
- ;;
- -h|--host) shift
- BUS_HOST=$1
- ;;
- -p|--port) shift
- BUS_PORT=$1
- ;;
- -k|--key) shift
- API_KEY=$1
- ;;
- -s|--secret) shift
- API_SECRET=$1
- ;;
- -t|--topic) shift
- TOPIC=$1
- ;;
- -P|--producer-key) shift
- URL_CONTEXT="producers"
- PRODUCER_KEY=$1
- KEY=$1
- ;;
- -C|--consumer-key) shift
- URL_CONTEXT="consumers"
- CONSUMER_KEY=$1
- KEY=$1
- ;;
- *) usage
- exit 1
- ;;
- esac
- shift
+until [ -z "$1" ]; do
+ case $1 in
+ -d|--debug) set -x
+ ;;
+ -h|--host) shift
+ BUS_HOST=$1
+ ;;
+ -p|--port) shift
+ BUS_PORT=$1
+ ;;
+ -k|--key) shift
+ API_KEY=$1
+ ;;
+ -s|--secret) shift
+ API_SECRET=$1
+ ;;
+ -t|--topic) shift
+ TOPIC=$1
+ ;;
+ -P|--producer-key) shift
+ URL_CONTEXT="producers"
+ PRODUCER_KEY=$1
+ KEY=$1
+ ;;
+ -C|--consumer-key) shift
+ URL_CONTEXT="consumers"
+ CONSUMER_KEY=$1
+ KEY=$1
+ ;;
+ *) usage
+ exit 1
+ ;;
+ esac
+ shift
done
-if [[ -z ${BUS_HOST} ]]; then
- echo "An UEB/DMAAP server must be provided."
- echo
- usage
- exit 1
+if [ -z "${BUS_HOST}" ]; then
+ echo "An UEB/DMAAP server must be provided."
+ echo
+ usage
+ exit 1
fi
-if [[ -z ${API_KEY} ]]; then
- echo "The API Key must be provided."
- usage
- exit 2
+if [ -z "${API_KEY}" ]; then
+ echo "The API Key must be provided."
+ usage
+ exit 2
fi
-if [[ -z ${API_SECRET} ]]; then
- echo "The API Secret must be provided."
- usage
- exit 3
+if [ -z "${API_SECRET}" ]; then
+ echo "The API Secret must be provided."
+ usage
+ exit 3
fi
-if [[ -z ${TOPIC} ]]; then
- echo "The Topic Name must be provided."
- usage
- exit 3
+if [ -z "${TOPIC}" ]; then
+ echo "The Topic Name must be provided."
+ usage
+ exit 3
fi
-if [[ -z ${PRODUCER_KEY} && -z ${CONSUMER_KEY} ]]; then
- echo "Either the Producer or Consumer options must be provided."
- usage
- exit 4
+if [ -z "${PRODUCER_KEY}" ] && [ -z "${CONSUMER_KEY}" ]; then
+ echo "Either the Producer or Consumer options must be provided."
+ usage
+ exit 4
fi
-if [[ -n ${PRODUCER_KEY} && -n ${CONSUMER_KEY} ]]; then
- echo "Only and only one of the Producer or Consumer options must be provided."
- usage
- exit 5
+if [ -n "${PRODUCER_KEY}" ] && [ -n "${CONSUMER_KEY}" ]; then
+ echo "Only and only one of the Producer or Consumer options must be provided."
+ usage
+ exit 5
fi
@@ -114,9 +114,9 @@ DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | ope
unset http_proxy
curl --silent -X PUT \
- --header "Accept:" \
- --header "X-CambriaDate: ${DATE}" \
- --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
- --header "Content-Type: application/json" \
- --data "{}" \
- http://${BUS_HOST}:${BUS_PORT}/topics/${TOPIC}/${URL_CONTEXT}/${KEY}
+ --header "Accept:" \
+ --header "X-CambriaDate: ${DATE}" \
+ --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
+ --header "Content-Type: application/json" \
+ --data "{}" \
+ http://${BUS_HOST}:${BUS_PORT}/topics/${TOPIC}/${URL_CONTEXT}/${KEY}
diff --git a/policy-management/src/main/server-gen/bin/create-api-key b/policy-management/src/main/server-gen/bin/create-api-key
index ea0ec7ad..d5af491f 100644
--- a/policy-management/src/main/server-gen/bin/create-api-key
+++ b/policy-management/src/main/server-gen/bin/create-api-key
@@ -1,17 +1,17 @@
-#! /bin/bash
+#!/usr/bin/env ash
###
# ============LICENSE_START=======================================================
# policy-management
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -21,56 +21,56 @@
###
function usage() {
- echo -n "Usage: $(basename $0) "
- echo -n "[(-d|--debug)] "
- echo -n "(-h|--host) <bus-host> "
- echo -n "[(-p|--port) <bus-port>] "
- echo "(-e|--email) <email>"
+ echo -n "Usage: $(basename $0) "
+ echo -n "[(-d|--debug)] "
+ echo -n "(-h|--host) <bus-host> "
+ echo -n "[(-p|--port) <bus-port>] "
+ echo "(-e|--email) <email>"
}
BUS_PORT=3904
# command line options parsing
-until [[ -z "$1" ]]; do
- case $1 in
- -d|--debug) set -x
- ;;
- -h|--host) shift
- BUS_HOST=$1
- ;;
- -p|--port) shift
- BUS_PORT=$1
- ;;
- -e|--email) shift
- EMAIL=$1
- ;;
- *) usage
- exit 1
- ;;
- esac
- shift
+until [ -z "$1" ]; do
+ case $1 in
+ -d|--debug) set -x
+ ;;
+ -h|--host) shift
+ BUS_HOST=$1
+ ;;
+ -p|--port) shift
+ BUS_PORT=$1
+ ;;
+ -e|--email) shift
+ EMAIL=$1
+ ;;
+ *) usage
+ exit 1
+ ;;
+ esac
+ shift
done
-if [[ -z ${BUS_HOST} ]]; then
- echo "An UEB/DMAAP server must be provided."
- echo
- usage
- exit 1
+if [ -z "${BUS_HOST}" ]; then
+ echo "An UEB/DMAAP server must be provided."
+ echo
+ usage
+ exit 1
fi
-if [[ -z ${EMAIL} ]]; then
- echo "An email address must be provided."
- usage
- exit 2
+if [ -z "${EMAIL}" ]; then
+ echo "An email address must be provided."
+ usage
+ exit 2
fi
-REQUEST_API_KEY_BODY=$(< <(cat <<EOF
+REQUEST_API_KEY_BODY=$(cat <<EOF
{
"email": "${EMAIL}",
"description": "Generated by PDP-D $(hostname -f)"
}
EOF
-))
+)
unset http_proxy
curl -s -X POST --data "${REQUEST_API_KEY_BODY}" --header "Content-Type: application/json" http://${BUS_HOST}:${BUS_PORT}/v1/apiKeys/create
diff --git a/policy-management/src/main/server-gen/bin/create-secured-topic b/policy-management/src/main/server-gen/bin/create-secured-topic
index b0d4d6f2..6e058142 100644
--- a/policy-management/src/main/server-gen/bin/create-secured-topic
+++ b/policy-management/src/main/server-gen/bin/create-secured-topic
@@ -1,17 +1,17 @@
-#! /bin/bash
+#!/usr/bin/env ash
###
# ============LICENSE_START=======================================================
# policy-management
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -21,16 +21,16 @@
###
function usage() {
- echo -n "Usage: $(basename $0) "
- echo -n "[(-d|--debug)] "
- echo -n "(-h|--host) <bus-host> "
- echo -n "[(-p|--port) <bus-port>] "
- echo -n "(-k|--key) <api-key> "
- echo -n "(-s|--secret) <api-secret> "
- echo -n "[(-P|--partition) <partition-count>] "
- echo -n "[(-R|--replication) <replication-count>] "
- echo "(-t|--topic) <topic> "
- echo ""
+ echo -n "Usage: $(basename $0) "
+ echo -n "[(-d|--debug)] "
+ echo -n "(-h|--host) <bus-host> "
+ echo -n "[(-p|--port) <bus-port>] "
+ echo -n "(-k|--key) <api-key> "
+ echo -n "(-s|--secret) <api-secret> "
+ echo -n "[(-P|--partition) <partition-count>] "
+ echo -n "[(-R|--replication) <replication-count>] "
+ echo "(-t|--topic) <topic> "
+ echo ""
}
BUS_PORT=3904
@@ -38,81 +38,81 @@ PARTITION_COUNT=1
REPLICATION_COUNT=1
# command line options parsing
-until [[ -z "$1" ]]; do
- case $1 in
- -d|--debug) set -x
- ;;
- -h|--host) shift
- BUS_HOST=$1
- ;;
- -p|--port) shift
- BUS_PORT=$1
- ;;
- -k|--key) shift
- API_KEY=$1
- ;;
- -s|--secret) shift
- API_SECRET=$1
- ;;
- -t|--topic) shift
- TOPIC=$1
- ;;
- -P|--partition-count) shift
- PARTITION_COUNT=$1
- ;;
- -R|--replication-count) shift
- REPLICATION_COUNT=$1
- ;;
- *) usage
- exit 1
- ;;
- esac
- shift
+until [ -z "$1" ]; do
+ case $1 in
+ -d|--debug) set -x
+ ;;
+ -h|--host) shift
+ BUS_HOST=$1
+ ;;
+ -p|--port) shift
+ BUS_PORT=$1
+ ;;
+ -k|--key) shift
+ API_KEY=$1
+ ;;
+ -s|--secret) shift
+ API_SECRET=$1
+ ;;
+ -t|--topic) shift
+ TOPIC=$1
+ ;;
+ -P|--partition-count) shift
+ PARTITION_COUNT=$1
+ ;;
+ -R|--replication-count) shift
+ REPLICATION_COUNT=$1
+ ;;
+ *) usage
+ exit 1
+ ;;
+ esac
+ shift
done
-if [[ -z ${BUS_HOST} ]]; then
- echo "An UEB/DMAAP server must be provided."
- echo
- usage
- exit 1
+if [ -z "${BUS_HOST}" ]; then
+ echo "An UEB/DMAAP server must be provided."
+ echo
+ usage
+ exit 1
fi
-if [[ -z ${API_KEY} ]]; then
- echo "The API Key must be provided."
- usage
- exit 2
+if [ -z "${API_KEY}" ]; then
+ echo "The API Key must be provided."
+ usage
+ exit 2
fi
-if [[ -z ${API_SECRET} ]]; then
- echo "The API Secret must be provided."
- usage
- exit 3
+if [ -z "${API_SECRET}" ]; then
+ echo "The API Secret must be provided."
+ usage
+ exit 3
fi
-if [[ -z ${TOPIC} ]]; then
- echo "The Topic Name must be provided."
- usage
- exit 3
+if [ -z "${TOPIC}" ]; then
+ echo "The Topic Name must be provided."
+ usage
+ exit 3
fi
-if [[ -z ${PARTITION_COUNT} ]]; then
- echo "The Partition Count must be provided."
- usage
- exit 4
+if [ -z "${PARTITION_COUNT}" ]; then
+ echo "The Partition Count must be provided."
+ usage
+ exit 4
fi
-if [[ -z ${REPLICATION_COUNT} ]]; then
- echo "The Replication Count must be provided."
- usage
- exit 5
+if [ -z "${REPLICATION_COUNT}" ]; then
+ echo "The Replication Count must be provided."
+ usage
+ exit 5
fi
REQUEST_API_KEY_BODY=$(< <(cat <<EOF
{
- "topicName": "${TOPIC}",
- "topicDescription": "Generated by PDP-D $(hostname -f)",
- "partitionCount": ${PARTITION_COUNT},
- "replicationCount": ${REPLICATION_COUNT}
+ "topicName": "${TOPIC}",
+ "topicDescription": "Generated by PDP-D $(hostname -f)",
+ "partitionCount": ${PARTITION_COUNT},
+ "replicationCount": ${REPLICATION_COUNT}
}
EOF
))
@@ -122,9 +122,9 @@ DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | ope
unset http_proxy
curl --silent -X POST \
- --header "Accept:" \
- --header "X-CambriaDate: ${DATE}" \
- --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
- --header "Content-Type: application/json" \
- --data "${REQUEST_API_KEY_BODY}" \
- http://${BUS_HOST}:${BUS_PORT}/topics/create
+ --header "Accept:" \
+ --header "X-CambriaDate: ${DATE}" \
+ --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
+ --header "Content-Type: application/json" \
+ --data "${REQUEST_API_KEY_BODY}" \
+ http://${BUS_HOST}:${BUS_PORT}/topics/create
diff --git a/policy-management/src/main/server-gen/bin/db-migrator b/policy-management/src/main/server-gen/bin/db-migrator
index f5029460..db82fc35 100644
--- a/policy-management/src/main/server-gen/bin/db-migrator
+++ b/policy-management/src/main/server-gen/bin/db-migrator
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -20,44 +20,43 @@
# #####################################################################
#
-# Upgrade/Downgrade SQL File Name Format:
+# Upgrade/Downgrade SQL File Name Format:
#
-# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql
+# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql
#
# This tool operates on a migration working directory at
-#
-# $POLICY_HOME/etc/db/migration
#
-# Upgrade/Downgrade files for each schema (aka database) names to be maintained
+# $POLICY_HOME/etc/db/migration
+#
+# Upgrade/Downgrade files for each schema (aka database) names to be maintained
# by this tool are located at
#
-# $POLICY_HOME/etc/db/migration/<schema-name>/sql
+# $POLICY_HOME/etc/db/migration/<schema-name>/sql
#
# The nature of the migration directories is dynamic.
# Other tooling aware of when migrations are needed are in charge to populate
-# the migrations directory accordingly.
+# the migrations directory accordingly.
#
# One of these tools is the 'features' when a feature with DB requirements
# is 'enabled', the upgrade scripts will be made present in the migration directory.
# When a features is 'disabled' downgrade scripts will be made available in the
# migration directory.
#
-# The 'policy' tool via its operations 'status' or 'start' will signal the
+# The 'policy' tool via its operations 'status' or 'start' will signal the
# need to perform upgrade or downgrade for a given schema.
#
# At any given time the following invariant must be preserved in any given
# $POLICY_HOME/etc/db/migration/<schema-name>/sql directory
#
-# There is only upgrade scripts, or only downgrade scripts, or none.
+# There is only upgrade scripts, or only downgrade scripts, or none.
#
# #####################################################################
source ${POLICY_HOME}/etc/profile.d/env.sh
METADATA_DB=migration
-METADATA_TABLE="${METADATA_DB}".metadata_versions
-MIGRATION_DIR="${POLICY_HOME}"/etc/db/migration
-
+METADATA_TABLE=${METADATA_DB}.metadata_versions
+MIGRATION_DIR=${POLICY_HOME}/etc/db/migration
ZERO_VERSION="0"
UPGRADE_SQL_SUFFIX=".upgrade.sql"
DOWNGRADE_SQL_SUFFIX=".downgrade.sql"
@@ -69,33 +68,33 @@ SQL_QUOTES="SET SESSION SQL_MODE=ANSI_QUOTES;"
#####################################################
function usage() {
- echo
- echo -e "syntax: $(basename "$0") "
- echo -e "\t -s <schema-name> "
- echo -e "\t [-b <migration-dir>] "
- echo -e "\t [-f <from-version>]"
- echo -e "\t [-t <target-version>]"
- echo -e "\t -o <operations> "
- echo
- echo -e "\t where <operations>=upgrade|downgrade|auto|version|erase|report"
- echo
- echo
- echo -e "Configuration Options:"
- echo -e "\t -s|--schema|--database: schema to operate on ('ALL' to apply on all)"
- echo -e "\t -b|--basedir: overrides base DB migration directory"
- echo -e "\t -f|--from: overrides current release version for operations"
- echo -e "\t -t|--target: overrides target release to upgrade/downgrade"
- echo
- echo -e "Operations:"
- echo -e "\t upgrade: upgrade operation"
- echo -e "\t downgrade: performs a downgrade operation"
- echo -e "\t auto: autonomous operation, determines upgrade or downgrade"
- echo -e "\t version: returns current version, and in conjunction if '-f' sets the current version"
- echo -e "\t erase: erase all data related <schema> (use with care)"
- echo -e "\t report: migration detailed report on an schema"
- echo -e "\t ok: is the migration status valid"
- echo
- echo
+ echo
+ echo -e "syntax: $(basename "$0") "
+ echo -e "\t -s <schema-name> "
+ echo -e "\t [-b <migration-dir>] "
+ echo -e "\t [-f <from-version>]"
+ echo -e "\t [-t <target-version>]"
+ echo -e "\t -o <operations> "
+ echo
+ echo -e "\t where <operations>=upgrade|downgrade|auto|version|erase|report"
+ echo
+ echo
+ echo -e "Configuration Options:"
+ echo -e "\t -s|--schema|--database: schema to operate on ('ALL' to apply on all)"
+ echo -e "\t -b|--basedir: overrides base DB migration directory"
+ echo -e "\t -f|--from: overrides current release version for operations"
+ echo -e "\t -t|--target: overrides target release to upgrade/downgrade"
+ echo
+ echo -e "Operations:"
+ echo -e "\t upgrade: upgrade operation"
+ echo -e "\t downgrade: performs a downgrade operation"
+ echo -e "\t auto: autonomous operation, determines upgrade or downgrade"
+ echo -e "\t version: returns current version, and in conjunction if '-f' sets the current version"
+ echo -e "\t erase: erase all data related <schema> (use with care)"
+ echo -e "\t report: migration detailed report on an schema"
+ echo -e "\t ok: is the migration status valid"
+ echo
+ echo
}
#####################################################
@@ -104,24 +103,24 @@ function usage() {
function ensure_metadata
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local sql rc
-
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- ensure_metadata --"
+ set -x
+ fi
+
+ local sql rc
+
sql="CREATE DATABASE IF NOT EXISTS ${METADATA_DB};"
- ${MYSQL} --execute "${sql}"
- rc=$?
- if [[ ${rc} != 0 ]]; then
- return ${rc}
- fi
-
+ ${MYSQL} --execute "${sql}"
+ rc=$?
+ if [ ${rc} -ne 0 ]; then
+ return ${rc}
+ fi
+
sql="CREATE TABLE IF NOT EXISTS ${METADATA_TABLE} "
- sql+="(name VARCHAR(60) NOT NULL, version VARCHAR(20), PRIMARY KEY(name));"
- ${MYSQL} --execute "${sql}"
- return $?
+ sql=${sql}"(name VARCHAR(60) NOT NULL, version VARCHAR(20), PRIMARY KEY(name));"
+ ${MYSQL} --execute "${sql}"
+ return $?
}
@@ -131,26 +130,26 @@ function ensure_metadata
function ensure_metadata_schema
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local sql rc
-
- sql="CREATE TABLE IF NOT EXISTS ${METADATA_HISTORY} "
- sql+="(script VARCHAR(80) NOT NULL, operation VARCHAR(10), success VARCHAR(1), "
- sql+="atTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "
- sql+="PRIMARY KEY(script));"
- ${MYSQL} --execute "${sql}"
- rc=$?
- if [[ ${rc} != 0 ]]; then
- return ${rc}
- fi
-
- sql="CREATE DATABASE IF NOT EXISTS ${SCHEMA_DB};"
- ${MYSQL} --execute "${sql}"
- return $?
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- ensure_metadata_schema --"
+ set -x
+ fi
+
+ local sql rc
+
+ sql="CREATE TABLE IF NOT EXISTS ${METADATA_HISTORY} "
+ sql=${sql}"(script VARCHAR(80) NOT NULL, operation VARCHAR(10), success VARCHAR(1), "
+ sql=${sql}"atTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "
+ sql=${sql}"PRIMARY KEY(script));"
+ ${MYSQL} --execute "${sql}"
+ rc=$?
+ if [ ${rc} -ne 0 ]; then
+ return ${rc}
+ fi
+
+ sql="CREATE DATABASE IF NOT EXISTS ${SCHEMA_DB};"
+ ${MYSQL} --execute "${sql}"
+ return $?
}
@@ -160,25 +159,25 @@ function ensure_metadata_schema
function target_release
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local sql sqlName upgradeSqls downgradeSqls
-
- TARGET_UPGRADE_RELEASE=${ZERO_VERSION}
- TARGET_DOWNGRADE_RELEASE=${ZERO_VERSION}
-
- upgradeSqls=$(ls -v -r "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null)
- for sql in ${upgradeSqls}; do
- sqlName=$(basename "${sql}")
- TARGET_UPGRADE_RELEASE="${sqlName%-*}"
- break
- done
-
- # default unless overriden
- TARGET_DOWNGRADE_RELEASE="${ZERO_VERSION}"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- target_release --"
+ set -x
+ fi
+
+ local sql sqlName upgradeSqls downgradeSqls
+
+ TARGET_UPGRADE_RELEASE=${ZERO_VERSION}
+ TARGET_DOWNGRADE_RELEASE=${ZERO_VERSION}
+
+ upgradeSqls=$(ls -v -r "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null)
+ for sql in ${upgradeSqls}; do
+ sqlName=$(basename "${sql}")
+ TARGET_UPGRADE_RELEASE="${sqlName%-*}"
+ break
+ done
+
+ # default unless overriden
+ TARGET_DOWNGRADE_RELEASE="${ZERO_VERSION}"
}
#####################################################
@@ -187,19 +186,19 @@ function target_release
function is_upgrade
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local upgradeSqls
-
- upgradeSqls=$(ls "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null)
- if [[ -z ${upgradeSqls} ]]; then
- return 1
- else
- return 0
- fi
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- is_upgrade --"
+ set -x
+ fi
+
+ local upgradeSqls
+
+ upgradeSqls=$(ls "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null)
+ if [ -z ${upgradeSqls} ]; then
+ return 1
+ else
+ return 0
+ fi
}
@@ -209,67 +208,66 @@ function is_upgrade
function is_downgrade
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local downgradeSqls
-
- downgradeSqls=$(ls "${DOWNGRADE_DIR}"/*"${DOWNGRADE_SQL_SUFFIX}" 2> /dev/null)
- if [[ -z ${downgradeSqls} ]]; then
- return 1
- else
- return 0
- fi
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- is_downgrade --"
+ set -x
+ fi
+
+ local downgradeSqls
+
+ downgradeSqls=$(ls "${DOWNGRADE_DIR}"/*"${DOWNGRADE_SQL_SUFFIX}" 2> /dev/null)
+ if [ -z ${downgradeSqls} ]; then
+ return 1
+ else
+ return 0
+ fi
}
#####################################################
-# current_release
+# set_current_release
#####################################################
-function current_release
+function set_current_release
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local rc
- local query="SELECT version FROM ${METADATA_TABLE} WHERE name='${SCHEMA}'"
-
- CURRENT_RELEASE=$(${MYSQL} --skip-column-names --silent --execute "${query}")
- if [[ -z ${CURRENT_RELEASE} ]]; then
- set_current_release "${ZERO_VERSION}"
- return $?
- fi
-
- return 0
-}
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- set_current_release --"
+ set -x
+ fi
+
+ CURRENT_RELEASE="${1}"
+ local sql
+ sql="INSERT INTO ${METADATA_TABLE} (name, version) "
+ sql=${sql}"VALUES('${SCHEMA}', '${CURRENT_RELEASE}') "
+ sql=${sql}"ON DUPLICATE KEY UPDATE version='${CURRENT_RELEASE}';"
+
+ ${MYSQL} --execute "${sql}"
+ return $?
+}
#####################################################
-# set_current_release
+# current_release
#####################################################
-function set_current_release
+function current_release
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- CURRENT_RELEASE="${1}"
-
- local sql="INSERT INTO ${METADATA_TABLE} (name, version) "
- sql+="VALUES('${SCHEMA}', '${CURRENT_RELEASE}') "
- sql+="ON DUPLICATE KEY UPDATE version='${CURRENT_RELEASE}';"
-
- ${MYSQL} --execute "${sql}"
- return $?
-}
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- current_release --"
+ set -x
+ fi
+ local rc
+ local query="SELECT version FROM ${METADATA_TABLE} WHERE name='${SCHEMA}'"
+
+ CURRENT_RELEASE=$(${MYSQL} --skip-column-names --silent --execute "${query}")
+ if [ -z "${CURRENT_RELEASE}" ]; then
+ set_current_release "${ZERO_VERSION}"
+ return $?
+ fi
+
+ return 0
+}
#####################################################
# execute sql script history
@@ -277,18 +275,18 @@ function set_current_release
function track_script
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local script="${1}" operation="${2}" success="${3}"
- local sql="INSERT INTO ${METADATA_HISTORY}(script,operation,success,atTime) "
- sql+="VALUES ('${script}','${operation}','${success}',now()) "
- sql+="ON DUPLICATE KEY UPDATE operation=values(operation), success=values(success), atTime=values(atTime);"
-
- ${MYSQL} --execute "${sql}"
- return $?
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- track_script $* --"
+ set -x
+ fi
+
+ local script="${1}" operation="${2}" success="${3}"
+ local sql="INSERT INTO ${METADATA_HISTORY}(script,operation,success,atTime) "
+ sql=${sql}"VALUES ('${script}','${operation}','${success}',now()) "
+ sql=${sql}"ON DUPLICATE KEY UPDATE operation=values(operation), success=values(success), atTime=values(atTime);"
+
+ ${MYSQL} --execute "${sql}"
+ return $?
}
@@ -298,27 +296,27 @@ function track_script
function run_script
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local operation="${1}" script="${2}" scriptPath="${3}"
-
- echo
- echo "> ${operation} ${script}"
-
- ${MYSQL} --verbose < "${scriptPath}"
- local rc=$?
- if [[ ${rc} != 0 ]]; then
- success="0"
- else
- success="1"
- fi
-
- track_script "${script}" "${operation}" "${success}"
-
- return ${rc}
+ if [ "${DEBUG}" == "y" ]]; then
+ echo "-- run_script $* --"
+ set -x
+ fi
+
+ local operation="${1}" script="${2}" scriptPath="${3}"
+
+ echo
+ echo "> ${operation} ${script}"
+
+ ${MYSQL} --verbose < "${scriptPath}"
+ local rc=$?
+ if [ ${rc} -ne 0 ]; then
+ success="0"
+ else
+ success="1"
+ fi
+
+ track_script "${script}" "${operation}" "${success}"
+
+ return ${rc}
}
#####################################################
@@ -327,38 +325,38 @@ function run_script
function upgrade
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local sqlName sqlFile schemaVersion upgradeSqls rc
-
- ${MYSQL} --execute "USE ${SCHEMA_DB}"
-
- echo "upgrade: ${CURRENT_RELEASE} -> ${TARGET_UPGRADE_RELEASE}"
-
- if [[ ${CURRENT_RELEASE} < ${TARGET_UPGRADE_RELEASE} ]]; then
- upgradeSqls=$(ls -v "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null)
- for sqlFile in ${upgradeSqls}; do
- sqlName=$(basename "${sqlFile}")
- schemaVersion="${sqlName%-*}"
- if [ "${schemaVersion}" -gt "${CURRENT_RELEASE}" ] && \
- [ "${schemaVersion}" -le "${TARGET_UPGRADE_RELEASE}" ]; then
- run_script "upgrade" "${sqlName}" "${sqlFile}"
- rc=$?
- if [[ ${rc} != 0 ]]; then
- echo "${SCHEMA}: upgrade aborted at ${schemaVersion} by script ${sqlName}"
- set_current_release "${schemaVersion}"
- return ${rc}
- fi
- fi
- done
-
- set_current_release "${TARGET_UPGRADE_RELEASE}"
- fi
-
- return 0
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- upgrade --"
+ set -x
+ fi
+
+ local sqlName sqlFile schemaVersion upgradeSqls rc
+
+ ${MYSQL} --execute "USE ${SCHEMA_DB}"
+
+ echo "upgrade: ${CURRENT_RELEASE} -> ${TARGET_UPGRADE_RELEASE}"
+
+ if [ ${CURRENT_RELEASE} \< ${TARGET_UPGRADE_RELEASE} ]; then
+ upgradeSqls=$(ls -v "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null)
+ for sqlFile in ${upgradeSqls}; do
+ sqlName=$(basename "${sqlFile}")
+ schemaVersion="${sqlName%-*}"
+ if [ "${schemaVersion}" -gt "${CURRENT_RELEASE}" ] && \
+ [ ! "${schemaVersion}" -le "${TARGET_UPGRADE_RELEASE}" ]; then
+ run_script "upgrade" "${sqlName}" "${sqlFile}"
+ rc=$?
+ if [ ${rc} -ne 0 ]; then
+ echo "${SCHEMA}: upgrade aborted at ${schemaVersion} by script ${sqlName}"
+ set_current_release "${schemaVersion}"
+ return ${rc}
+ fi
+ fi
+ done
+
+ set_current_release "${TARGET_UPGRADE_RELEASE}"
+ fi
+
+ return 0
}
#####################################################
@@ -367,38 +365,38 @@ function upgrade
function downgrade
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local sqlName sqlFile schemaVersion downgradeSqls rc
-
- ${MYSQL} --execute "USE ${SCHEMA_DB}"
-
- echo "downgrade: ${CURRENT_RELEASE} -> ${TARGET_DOWNGRADE_RELEASE}"
-
- if [[ ${CURRENT_RELEASE} > ${TARGET_DOWNGRADE_RELEASE} ]]; then
- downgradeSqls=$(ls -v -r "${DOWNGRADE_DIR}"/*"${DOWNGRADE_SQL_SUFFIX}" 2> /dev/null)
- for sqlFile in ${downgradeSqls}; do
- sqlName=$(basename "${sqlFile}")
- schemaVersion="${sqlName%-*}"
- if [ "${schemaVersion}" -le "${CURRENT_RELEASE}" ] && \
- [ "${schemaVersion}" -gt "${TARGET_DOWNGRADE_RELEASE}" ]; then
- run_script "downgrade" "${sqlName}" "${sqlFile}"
- rc=$?
- if [[ ${rc} != 0 ]]; then
- echo "${SCHEMA}: downgrade aborted at ${schemaVersion} by script ${sqlName}"
- set_current_release "${schemaVersion}"
- return ${rc}
- fi
- fi
- done
-
- set_current_release "${TARGET_DOWNGRADE_RELEASE}"
- fi
-
- return 0
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- downgrade --"
+ set -x
+ fi
+
+ local sqlName sqlFile schemaVersion downgradeSqls rc
+
+ ${MYSQL} --execute "USE ${SCHEMA_DB}"
+
+ echo "downgrade: ${CURRENT_RELEASE} -> ${TARGET_DOWNGRADE_RELEASE}"
+
+ if [ ${CURRENT_RELEASE} \> ${TARGET_DOWNGRADE_RELEASE} ]; then
+ downgradeSqls=$(ls -v -r "${DOWNGRADE_DIR}"/*"${DOWNGRADE_SQL_SUFFIX}" 2> /dev/null)
+ for sqlFile in ${downgradeSqls}; do
+ sqlName=$(basename "${sqlFile}")
+ schemaVersion="${sqlName%-*}"
+ if [ "${schemaVersion}" -le "${CURRENT_RELEASE}" ] && \
+ [ "${schemaVersion}" -gt "${TARGET_DOWNGRADE_RELEASE}" ]; then
+ run_script "downgrade" "${sqlName}" "${sqlFile}"
+ rc=$?
+ if [ ${rc} -ne 0 ]; then
+ echo "${SCHEMA}: downgrade aborted at ${schemaVersion} by script ${sqlName}"
+ set_current_release "${schemaVersion}"
+ return ${rc}
+ fi
+ fi
+ done
+
+ set_current_release "${TARGET_DOWNGRADE_RELEASE}"
+ fi
+
+ return 0
}
#####################################################
@@ -407,19 +405,19 @@ function downgrade
function erase
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local updateMetadata="UPDATE ${METADATA_TABLE} SET version='${ZERO_VERSION}';"
- ${MYSQL} --execute "${updateMetadata}"
-
- local deleteHistory="DELETE FROM ${METADATA_HISTORY};"
- ${MYSQL} --execute "${deleteHistory}"
-
- local dropDB="DROP DATABASE IF EXISTS ${SCHEMA_DB}";
- ${MYSQL} --execute "${dropDB}"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- erase --"
+ set -x
+ fi
+
+ local updateMetadata="UPDATE ${METADATA_TABLE} SET version='${ZERO_VERSION}';"
+ ${MYSQL} --execute "${updateMetadata}"
+
+ local deleteHistory="DELETE FROM ${METADATA_HISTORY};"
+ ${MYSQL} --execute "${deleteHistory}"
+
+ local dropDB="DROP DATABASE IF EXISTS ${SCHEMA_DB}";
+ ${MYSQL} --execute "${dropDB}"
}
#####################################################
@@ -428,202 +426,201 @@ function erase
function report
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local versionSql="SELECT * FROM ${METADATA_TABLE} WHERE name='${SCHEMA}';"
- ${MYSQL} --execute "${versionSql}"
-
- local historySql="SELECT * FROM ${METADATA_HISTORY} ORDER BY atTime ASC;"
- ${MYSQL} --execute "${historySql}"
-
- okay
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- report --"
+ set -x
+ fi
+
+ local versionSql="SELECT * FROM ${METADATA_TABLE} WHERE name='${SCHEMA}';"
+ ${MYSQL} --execute "${versionSql}"
+
+ local historySql="SELECT * FROM ${METADATA_HISTORY} ORDER BY atTime ASC;"
+ ${MYSQL} --execute "${historySql}"
+
+ okay
}
function okay
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local rc=0
- if is_upgrade; then
- if [[ ${CURRENT_RELEASE} == "${TARGET_UPGRADE_RELEASE}" ]]; then
- echo "${SCHEMA}: OK @ ${CURRENT_RELEASE}"
- else
- echo "${SCHEMA}: upgrade available: ${CURRENT_RELEASE} -> ${TARGET_UPGRADE_RELEASE}"
- rc=1
- fi
- else
- if [[ ${CURRENT_RELEASE} == "${TARGET_DOWNGRADE_RELEASE}" ]]; then
- echo "${SCHEMA}: OK @ ${CURRENT_RELEASE}"
- else
- echo "${SCHEMA}: downgrade available: ${CURRENT_RELEASE} -> ${TARGET_DOWNGRADE_RELEASE}"
- rc=1
- fi
- fi
-
- return ${rc}
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- okay --"
+ set -x
+ fi
+
+ local rc=0
+ if is_upgrade; then
+ if [ "${CURRENT_RELEASE}" = "${TARGET_UPGRADE_RELEASE}" ]; then
+ echo "${SCHEMA}: OK @ ${CURRENT_RELEASE}"
+ else
+ echo "${SCHEMA}: upgrade available: ${CURRENT_RELEASE} -> ${TARGET_UPGRADE_RELEASE}"
+ rc=1
+ fi
+ else
+ if [ "${CURRENT_RELEASE}" = "${TARGET_DOWNGRADE_RELEASE}" ]; then
+ echo "${SCHEMA}: OK @ ${CURRENT_RELEASE}"
+ else
+ echo "${SCHEMA}: downgrade available: ${CURRENT_RELEASE} -> ${TARGET_DOWNGRADE_RELEASE}"
+ rc=1
+ fi
+ fi
+
+ return ${rc}
}
#####################################################
# MAIN
#####################################################
-if [[ ${DEBUG} == y ]]; then
- echo "-- $0 $* --"
- set -x
+if [ "${DEBUG}" = "y" ]; then
+ echo "-- $0 $* --"
+ set -x
fi
-
-until [[ -z "$1" ]]; do
- case $1 in
- -s|--schema|--database) shift
- SCHEMA=$1
- ;;
- -b|--basedir) shift
- MIGRATION_DIR=$1
- ;;
- -t|--target) shift
- INPUT_TARGET_RELEASE=$1
- ;;
- -f|--from) shift
- INPUT_CURRENT_RELEASE=$1
- ;;
- -o|--operation) shift
- OPERATION=$1
- ;;
- *) usage
- exit 1
- ;;
- esac
- shift
+until [ -z "$1" ]; do
+ case $1 in
+ -s|--schema|--database) shift
+ SCHEMA=$1
+ ;;
+ -b|--basedir) shift
+ MIGRATION_DIR=$1
+ ;;
+ -t|--target) shift
+ INPUT_TARGET_RELEASE=$1
+ ;;
+ -f|--from) shift
+ INPUT_CURRENT_RELEASE=$1
+ ;;
+ -o|--operation) shift
+ OPERATION=$1
+ ;;
+ *) usage
+ exit 1
+ ;;
+ esac
+ shift
done
case ${OPERATION} in
- upgrade) ;;
- downgrade) ;;
- auto) ;;
- version) ;;
- erase) ;;
- report) ;;
- ok) ;;
- *) echo "error: invalid operation provided"
- usage
- exit 1
- ;;
+ upgrade) ;;
+ downgrade) ;;
+ auto) ;;
+ version) ;;
+ erase) ;;
+ report) ;;
+ ok) ;;
+ *) echo "error: invalid operation provided"
+ usage
+ exit 1
+ ;;
esac
-if [[ -z ${SCHEMA} ]]; then
- echo "error: a database name must be provided"
- usage
- exit 2
+if [ -z "${SCHEMA}" ]; then
+ echo "error: a database name must be provided"
+ usage
+ exit 2
fi
source "${POLICY_HOME}"/etc/profile.d/env.sh
-if [[ -z ${SQL_HOST} ]] || [[ -z ${SQL_USER} ]] || [[ -z ${SQL_PASSWORD} ]]; then
- echo "error: no database has been set up"
- exit 4
+if [ -z "${SQL_HOST}" ] || [ -z "${SQL_USER}" ] || [ -z "${SQL_PASSWORD}" ]; then
+ echo "error: no database has been set up"
+ exit 4
fi
MYSQL="mysql -u${SQL_USER} -p${SQL_PASSWORD} -h ${SQL_HOST}";
if ! ${MYSQL} -h"${SQL_HOST}" --execute "show databases;" > /dev/null 2>&1; then
- echo "error: No DB connectivity to ${SQL_HOST} for ${SQL_USER}"
- exit 5
+ echo "error: No DB connectivity to ${SQL_HOST} for ${SQL_USER}"
+ exit 5
fi
-if [[ ${SCHEMA} == ALL ]]; then
- SCHEMA="*"
+if [ "${SCHEMA}" = "ALL" ]; then
+ SCHEMA="*"
fi
SCHEMA_S=$(ls -d "${MIGRATION_DIR}"/${SCHEMA}/ 2> /dev/null)
-if [[ -z ${SCHEMA_S} ]]; then
- echo "error: no databases available"
- exit 0
+if [ -z "${SCHEMA_S}" ]; then
+ echo "error: no databases available"
+ exit 0
fi
if ! ensure_metadata; then
- echo "error: migration metadata not accessible"
- exit 7
+ echo "error: migration metadata not accessible"
+ exit 7
fi
rc=0
for dbPath in ${SCHEMA_S}; do
- SCHEMA=$(basename "${dbPath}")
- SCHEMA_DB="\`${SCHEMA}\`"
- UPGRADE_DIR="${MIGRATION_DIR}"/"${SCHEMA}"/sql
- DOWNGRADE_DIR=${UPGRADE_DIR}
- METADATA_HISTORY="${METADATA_DB}.\`${SCHEMA}_history\`"
- TARGET_RELEASE=${INPUT_TARGET_RELEASE}
- CURRENT_RELEASE=${INPUT_CURRENT_RELEASE}
-
- if is_upgrade && is_downgrade; then
- echo "${SCHEMA}: failure: invalid configuration: ${UPGRADE_SQL_SUFFIX} and "\
- "${DOWNGRADE_SQL_SUFFIX} exist under ${DOWNGRADE_DIR}"
- rc=1
- continue
- fi
-
- if [[ ${operation} == auto ]]; then
- if is_upgrade; then
- operation=upgrade
- else
- operation=downgrade
- fi
- fi
-
- if ! ensure_metadata_schema; then
- echo "${SCHEMA}: failure: metadata not accessible for this schema"
- continue
- fi
-
- if [[ -z ${TARGET_RELEASE} ]]; then
- target_release
- else
- # user asked to override
- TARGET_UPGRADE_RELEASE="${TARGET_RELEASE}"
- TARGET_DOWNGRADE_RELEASE="${TARGET_RELEASE}"
- fi
-
- if [[ -z ${CURRENT_RELEASE} ]]; then
- if ! current_release; then
- echo "${SCHEMA}: failure: cannot obtain current release"
- continue
- fi
- else
- if ! set_current_release "${CURRENT_RELEASE}"; then
- echo "${SCHEMA}: failure: cannot set current release"
- continue
- fi
- fi
-
- case ${OPERATION} in
- upgrade) if upgrade; then
- echo "${SCHEMA}: OK: upgrade (${CURRENT_RELEASE})"
- else
- rc=1
- echo "${SCHEMA}: failure: upgrade to release ${TARGET_UPGRADE_RELEASE} (${CURRENT_RELEASE})"
- fi
- ;;
- downgrade) if downgrade; then
- echo "${SCHEMA}: OK: downgrade (${CURRENT_RELEASE})"
- else
- rc=1
- echo "${SCHEMA}: failure: downgrade to release ${TARGET_DOWNGRADE_RELEASE} (${CURRENT_RELEASE})"
- fi
- ;;
- version) echo "${SCHEMA}: ${CURRENT_RELEASE}"
- ;;
- erase) erase
- ;;
- report) report
- ;;
- ok) okay
- ;;
- esac
+ SCHEMA=$(basename "${dbPath}")
+ SCHEMA_DB="\`${SCHEMA}\`"
+ UPGRADE_DIR="${MIGRATION_DIR}"/"${SCHEMA}"/sql
+ DOWNGRADE_DIR=${UPGRADE_DIR}
+ METADATA_HISTORY="${METADATA_DB}.\`${SCHEMA}_history\`"
+ TARGET_RELEASE=${INPUT_TARGET_RELEASE}
+ CURRENT_RELEASE=${INPUT_CURRENT_RELEASE}
+
+ if is_upgrade && is_downgrade; then
+ echo "${SCHEMA}: failure: invalid configuration: ${UPGRADE_SQL_SUFFIX} and "\
+ "${DOWNGRADE_SQL_SUFFIX} exist under ${DOWNGRADE_DIR}"
+ rc=1
+ continue
+ fi
+
+ if [ "${operation}" = "auto" ]; then
+ if is_upgrade; then
+ operation=upgrade
+ else
+ operation=downgrade
+ fi
+ fi
+
+ if ! ensure_metadata_schema; then
+ echo "${SCHEMA}: failure: metadata not accessible for this schema"
+ continue
+ fi
+
+ if [ -z "${TARGET_RELEASE}" ]; then
+ target_release
+ else
+ # user asked to override
+ TARGET_UPGRADE_RELEASE="${TARGET_RELEASE}"
+ TARGET_DOWNGRADE_RELEASE="${TARGET_RELEASE}"
+ fi
+
+ if [ -z "${CURRENT_RELEASE}" ]; then
+ if ! current_release; then
+ echo "${SCHEMA}: failure: cannot obtain current release"
+ continue
+ fi
+ else
+ if ! set_current_release "${CURRENT_RELEASE}"; then
+ echo "${SCHEMA}: failure: cannot set current release"
+ continue
+ fi
+ fi
+
+ case ${OPERATION} in
+ upgrade) if upgrade; then
+ echo "${SCHEMA}: OK: upgrade (${CURRENT_RELEASE})"
+ else
+ rc=1
+ echo "${SCHEMA}: failure: upgrade to release ${TARGET_UPGRADE_RELEASE} (${CURRENT_RELEASE})"
+ fi
+ ;;
+ downgrade) if downgrade; then
+ echo "${SCHEMA}: OK: downgrade (${CURRENT_RELEASE})"
+ else
+ rc=1
+ echo "${SCHEMA}: failure: downgrade to release ${TARGET_DOWNGRADE_RELEASE} (${CURRENT_RELEASE})"
+ fi
+ ;;
+ version) echo "${SCHEMA}: ${CURRENT_RELEASE}"
+ ;;
+ erase) erase
+ ;;
+ report) report
+ ;;
+ ok) okay
+ ;;
+ esac
done
-exit ${rc}
+exit $rc
diff --git a/policy-management/src/main/server-gen/bin/deploy-artifact b/policy-management/src/main/server-gen/bin/deploy-artifact
index b25aaf9c..2ba42fb9 100644
--- a/policy-management/src/main/server-gen/bin/deploy-artifact
+++ b/policy-management/src/main/server-gen/bin/deploy-artifact
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -56,34 +56,35 @@ function usage() {
function init
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- init $* --"
set -x
fi
local artifact="${1}"
- if [[ ! -f ${artifact} ]]; then
+ if [ ! -f "${artifact}" ]; then
echo "${artifact}: artifact does not exist"
return 1
fi
- if [[ ${artifact} != *.jar ]]; then
+ if [ "${artifact}" = "${artifact%.jar}" ]; then
return 0
fi
local dir=$(mktemp -d)
local jar="${artifact##*/}"
+ CURRENT_DIR=$PWD
WORKING_DIR=$(realpath "${dir}")
cp -p "${artifact}" "${WORKING_DIR}/${jar}"
- pushd "${dir}"
+ cd "${WORKING_DIR}"
local rc=0
# determine name of 'pom' file within JAR
local pom=$(jar tf "${jar}" META-INF | grep '/pom\.xml$' | head -1)
- if [[ -n ${pom} ]] ; then
+ if [ -n "${pom}" ] ; then
jar xf "${jar}" "${pom}"
WORKING_POM=$(realpath "${pom}")
else
@@ -91,7 +92,7 @@ function init
fi
local pomProperties=$(jar tf "${jar}" META-INF | grep '/pom\.properties$' | head -1)
- if [[ -n ${pomProperties} ]]; then
+ if [ -n "${pomProperties}" ]; then
jar xf "${jar}" "${pomProperties}"
WORKING_POM_PROPERTIES=$(realpath ${pomProperties})
sed -i 's/\r$//' "${WORKING_POM_PROPERTIES}"
@@ -99,7 +100,7 @@ function init
echo "${artifact}: sourcing in ${WORKING_POM_PROPERTIES}"
else
echo "${artifact}: pom.properties not found"
- if [[ -n ${WORKING_POM} ]]; then
+ if [ -n "${WORKING_POM}" ]; then
if ! getPomAttributes "${WORKING_POM}" artifactId groupId version ; then
echo "${WORKING_POM}: cannot extract maven coordinates"
rc=1
@@ -109,14 +110,13 @@ function init
rc=1
fi
fi
-
- if [[ -z ${version} ]] || [[ -z ${groupId} ]] || [[ -z ${artifactId} ]]; then
+ if [ -z "${version}" ] || [ -z "${groupId}" ] || [ -z "${artifactId}" ]; then
echo "${artifact}: some coordinates cannot be extracted"
rc=1
fi
echo "${artifact}: coordinates ${groupId}:${artifactId}:${version}"
- popd
+ cd ${CURRENT_DIR}
return ${rc}
}
@@ -129,12 +129,12 @@ function init
function cleanup
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- cleanup $* --"
set -x
fi
- if [[ -n ${WORKING_DIR} ]]; then
+ if [ -n "${WORKING_DIR}" ]; then
rm -rf "${WORKING_DIR}"
fi
}
@@ -149,18 +149,18 @@ function cleanup
function getPomAttributes
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- getPomAttributes $* --"
set -x
fi
local file="$1"
- if [[ ! -f "${file}" ]]; then
+ if [ ! -f "${file}" ]; then
echo "${file}: file does not exist"
return 1
fi
- local tab=$'\t' rval=0 attr value
+ local rval=0 attr value
shift
for attr in "$@" ; do
@@ -177,10 +177,10 @@ function getPomAttributes
-e '/<packaging>/,/<\/packaging>/d' \
-e '/<modelVersion>/,/<\/modelVersion>/d' \
-e '/<properties>/,/<\/properties>/d' \
- -e "/^[ ${tab}]*<${attr}>\([^<]*\)<\/${attr}>.*/{s//\1/p;}" \
+ -e "/^[ \t]*<${attr}>\([^<]*\)<\/${attr}>.*/{s//\1/p;}" \
<"${file}")
- if [[ "${value}" == "" ]]; then
+ if [ -z "${value}" ]; then
# need to check parent for parameter
value=$(sed -n \
-e '/<dependencies>/,/<\/dependencies>/d' \
@@ -190,10 +190,10 @@ function getPomAttributes
-e '/<packaging>/,/<\/packaging>/d' \
-e '/<modelVersion>/,/<\/modelVersion>/d' \
-e '/<properties>/,/<\/properties>/d' \
- -e "/^[ ${tab}]*<${attr}>\([^<]*\)<\/${attr}>.*/{s//\1/p;}" \
+ -e "/^[ \t]*<${attr}>\([^<]*\)<\/${attr}>.*/{s//\1/p;}" \
<"${file}")
- if [[ "${value}" == "" ]] ; then
+ if [ -z "${value}" ] ; then
echo "${file}: Can't determine ${attr}"
rval=1
fi
@@ -201,7 +201,7 @@ function getPomAttributes
# the following sets an environment variable with the name referred
# to by ${attr}
- read "${attr}" <<<"${value}"
+ export ${attr}="${value}"
done
return ${rval}
}
@@ -213,16 +213,17 @@ function getPomAttributes
# extracting the attributes such as proxy host, port, username and password.
# These proxy attributes are set into the global variable for maven proxy
# settings to be used as build arguments with maven commands.
+# The http proxy format is: http_proxy="http://username:password@proxy.thing.com:8080"
##############################################################################
function setMavenProxyArgs
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- setMavenProxyArgs $* --"
set -x
fi
- if [[ -z ${http_proxy} ]]; then
+ if [ -z "${http_proxy}" ]; then
return 0
fi
@@ -232,11 +233,11 @@ function setMavenProxyArgs
local port="${proxy#*:}"
MVN_PROXY_SETTINGS="-DproxyHost=${host} -DproxyPort=${port}"
- if [[ "$proxy_creds" == *"@"* ]]; then
+ if echo "$proxy_creds" | egrep -s '@'; then
local creds="${proxy_creds%%@*}"
local username="${creds%:*}"
local password="${creds#*:}"
- MVN_PROXY_SETTINGS+=" -DproxyUsername=${username} -DproxyPassword=${password}"
+ MVN_PROXY_SETTINGS=${MVN_PROXY_SETTINGS}" -DproxyUsername=${username} -DproxyPassword=${password}"
fi
}
@@ -249,19 +250,19 @@ function setMavenProxyArgs
function deployJar
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- deployJar $* --"
set -x
fi
local file="${1}"
- if [[ ! -f ${file} ]]; then
+ if [ ! -f "${file}" ]; then
return 1
fi
local repoId repoUrl
- if [[ "${version}" =~ SNAPSHOT ]] ; then
+ if echo "$version" | egrep -s 'SNAPSHOT'; then
repoId=${SNAPSHOT_REPOSITORY_ID}
repoUrl=${SNAPSHOT_REPOSITORY_URL}
else
@@ -269,7 +270,7 @@ function deployJar
repoUrl=${RELEASE_REPOSITORY_URL}
fi
- if [[ -z ${repoUrl} ]] || [[ -z ${repoId} ]]; then
+ if [ -z "${repoUrl}" ] || [ -z "${repoId}" ]; then
echo "{file}: no repository id/url to deploy jar"
return 1
fi
@@ -298,14 +299,14 @@ function deployJar
function deployPom
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- deployPom $* --"
set -x
fi
local file="${1}"
- if [[ ! -f ${file} ]]; then
+ if [ ! -f "${file}" ]; then
return 1
fi
@@ -315,7 +316,7 @@ function deployPom
fi
local repoId repoUrl
- if [[ "${version}" =~ SNAPSHOT ]] ; then
+ if echo "$version" | egrep -s 'SNAPSHOT'; then
repoId=${SNAPSHOT_REPOSITORY_ID}
repoUrl=${SNAPSHOT_REPOSITORY_URL}
else
@@ -348,18 +349,18 @@ function deployPom
function deployArtifact
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- deployArtifact $* --"
set -x
fi
local file="${1}"
- if [[ -z "${file}" ]]; then
+ if [ -z "${file}" ]; then
echo "${file}: artifact file not provided"
return 1
fi
- if [[ ! -f "${file}" ]]; then
+ if [ ! -f "${file}" ]; then
echo "${file}: artifact file does not exist"
return 1
fi
@@ -387,19 +388,19 @@ function deployArtifact
function installJar
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- installJar $* --"
set -x
fi
local file="${1}"
- if [[ ! -f ${file} ]]; then
+ if [ ! -f "${file}" ]; then
return 1
fi
mvn ${CUSTOM_SETTINGS} ${MVN_PROXY_SETTINGS} \
- org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile="${file}"
+ org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=${file}
return $?
}
@@ -412,14 +413,14 @@ function installJar
function installPom
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- installPom $* --"
set -x
fi
local file="${1}"
- if [[ ! -f ${file} ]]; then
+ if [ ! -f "${file}" ]; then
return 1
fi
@@ -440,22 +441,21 @@ function installPom
function installArtifact
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- installArtifact $* --"
set -x
fi
local file="${1}"
- if [[ -z "${file}" ]]; then
+ if [ -z "${file}" ]; then
echo "${file}: artifact file not provided"
return 1
fi
- if [[ ! -f "${file}" ]]; then
+ if [ ! -f "${file}" ]; then
echo "${file}: artifact file does not exist"
return 1
fi
-
case "${file}" in
*pom.xml|*.pom)
installPom "${file}"
@@ -480,18 +480,18 @@ function installArtifact
function installDependencies
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- installDependencies $* --"
set -x
fi
local file="${1}"
- if [[ ! -f ${file} ]]; then
+ if [ ! -f "${file}" ]; then
return 1
fi
- if [[ -z ${DEPENDENCY_REPO_URL} ]]; then
+ if [ -z "${DEPENDENCY_REPO_URL}" ]; then
echo "${file}: no repo url to install dependencies"
return 1
fi
@@ -513,7 +513,7 @@ function installDependencies
# MAIN
##############################################################################
-if [[ ${DEBUG} == y ]]; then
+if [ "${DEBUG}" = "y" ]; then
echo "-- $0 $* --"
set -x
fi
@@ -534,7 +534,7 @@ unset MVN_PROXY_SETTINGS
# process input
-until [[ -z "$1" ]]; do
+until [ -z "$1" ]; do
case $1 in
-a|--artifact) shift
ARTIFACT_FILE=$1
@@ -555,13 +555,13 @@ until [[ -z "$1" ]]; do
shift
done
-if [[ -z ${ARTIFACT_FILE} ]]; then
+if [ -z "${ARTIFACT_FILE}" ]; then
echo "No artifact file provided: $*"
usage
exit 1
fi
-if [[ -n ${SETTINGS_FILE} ]]; then
+if [ -n "${SETTINGS_FILE}" ]; then
CUSTOM_SETTINGS="--settings=${SETTINGS_FILE}"
fi
@@ -576,7 +576,7 @@ retval=0
init "${ARTIFACT_FILE}"
retval=$?
-if [[ ${retval} != 0 ]]; then
+if [ ${retval} -ne 0 ]; then
cleanup
exit ${retval}
fi
@@ -586,14 +586,14 @@ fi
# SNAPSHOT_REPOSITORY_URL and RELEASE_REPOSITORY_URL
# are pre-existing environmental variables (base.conf)
-if [[ -n ${SNAPSHOT_REPOSITORY_URL} ]] || [[ -n ${RELEASE_REPOSITORY_URL} ]]; then
+if [ -n "${SNAPSHOT_REPOSITORY_URL}" ] || [ -n "${RELEASE_REPOSITORY_URL}" ]; then
deployArtifact "${ARTIFACT_FILE}"
retval=$(( retval + ${?} ))
fi
# deploy in file repository
-if [[ -n ${FILE_REPO_INSTALL} ]]; then
+if [ -n "${FILE_REPO_INSTALL}" ]; then
FILE_REPO_ID="file-repository"
FILE_REPO_URL="file:${HOME}/.m2/file-repository"
@@ -609,21 +609,21 @@ fi
# install in local repository
-if [[ -n ${LOCAL_INSTALL} ]]; then
+if [ -n "${LOCAL_INSTALL}" ]; then
installArtifact "${ARTIFACT_FILE}"
retval=$(( retval + ${?} ))
fi
# install dependencies in local and/or file repositories
-if [[ -n ${INSTALL_DEPS} ]]; then
- if [[ -n ${FILE_REPO_INSTALL} ]]; then
+if [ -n "${INSTALL_DEPS}" ]; then
+ if [ -n "${FILE_REPO_INSTALL}" ]; then
DEPENDENCY_REPO_URL="${FILE_REPO_URL}"
installDependencies "${ARTIFACT_FILE}"
retval=$(( retval + ${?} ))
fi
- if [[ -n ${LOCAL_INSTALL} ]]; then
+ if [ -n "${LOCAL_INSTALL}" ]; then
DEPENDENCY_REPO_URL="file:${HOME}/.m2/repository"
installDependencies "${ARTIFACT_FILE}"
retval=$(( retval + ${?} ))
diff --git a/policy-management/src/main/server-gen/bin/features b/policy-management/src/main/server-gen/bin/features
index 2646c04d..fc1f239f 100644
--- a/policy-management/src/main/server-gen/bin/features
+++ b/policy-management/src/main/server-gen/bin/features
@@ -1,17 +1,17 @@
-#!/usr/bin/env bash
+#!/usr/bin/env ash
###
# ============LICENSE_START=======================================================
# ONAP POLICY
# ================================================================================
-# Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
@@ -115,10 +115,10 @@
# in the pdp-d migration directory ($POLICY_HOME/etc/db/migration).
# 6. cd to the feature 'install' directory an executes (if exists) the 'disable' script to allow for specific
# customizations for this feature.
-#
+#
# Notes for DB enabled features:
-# A. Upgrade/Downgrade SQL File Name Format:
-# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql
+# A. Upgrade/Downgrade SQL File Name Format:
+# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql
# B. See related tooling: db-migrator, deploy-artifact, and policy
#
# Example:
@@ -145,11 +145,11 @@
# L─ feature-healthcheck-1.1.0-SNAPSHOT.jar
# #############################################################
-if [[ ${DEBUG} == y ]]; then
- echo "-- MAIN --"
- set -x
+if [ "${DEBUG}" = "y" ]; then
+ echo "-- MAIN --"
+ set -x
fi
-
+
# The directories at play
LIB=${POLICY_HOME}/lib
@@ -158,21 +158,21 @@ BIN=${POLICY_HOME}/bin
DB=${POLICY_HOME}/etc/db/migration
FEATURES=${POLICY_HOME}/features
-if [[ ! ( -d "${LIB}" && -x "${LIB}" ) ]]; then
- echo "error: no ${LIB} directory"
- exit 1
+if [ ! -d "${LIB}" ]; then
+ echo "error: no ${LIB} directory"
+ exit 1
fi
-if [[ ! ( -d "${CONFIG}" && -x "${CONFIG}" ) ]]; then
- echo "error: no ${CONFIG} directory"
- exit 2
+if [ ! -d "${CONFIG}" ]; then
+ echo "error: no ${CONFIG} directory"
+ exit 2
fi
# ensure that the directory exists
mkdir -p "${FEATURES}" 2> /dev/null
-if [[ ! -d "${DB}" ]]; then
- mkdir -p "${DB}"
+if [ ! -d "${DB}" ]; then
+ mkdir -p "${DB}"
fi
# relative per Feature Directory Paths
@@ -197,25 +197,25 @@ versionLength=15
# update field lengths, if needed
for jar in ${featureJars} ; do
- # get file name without 'jar' suffix
- tmp="${jar%\.jar}"
-
- # remove feature prefix
- tmp="${tmp#feature-}"
-
- # get feature name by removing the version portion
- name="${tmp%%-[0-9]*}"
-
- # extract version portion of name
- version="${tmp#${name}-}"
-
- # grow the size of the name/version field, if needed
- if (( "${#name}" > nameLength )) ; then
- nameLength="${#name}"
- fi
- if (( "${#version}" > versionLength )) ; then
- versionLength="${#version}"
- fi
+ # get file name without 'jar' suffix
+ tmp="${jar%\.jar}"
+
+ # remove feature prefix
+ tmp="${tmp#feature-}"
+
+ # get feature name by removing the version portion
+ name="${tmp%%-[0-9]*}"
+
+ # extract version portion of name
+ version="${tmp#${name}-}"
+
+ # grow the size of the name/version field, if needed
+ if [ ${#name} -gt $nameLength ] ; then
+ nameLength=${#name}
+ fi
+ if [ ${#version} -gt $versionLength ] ; then
+ versionLength=${#version}
+ fi
done
# ##########################################################
@@ -238,121 +238,121 @@ function usage
EOF
}
+
# ##########################################################
# status: dump out status information
# ##########################################################
function status
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local tmp name version status
- local format="%-${nameLength}s %-${versionLength}s %s\n"
-
- printf "${format}" "name" "version" "status"
- printf "${format}" "----" "-------" "------"
-
- for jar in ${featureJars} ; do
- # get file name without 'jar' suffix
- tmp="${jar%\.jar}"
-
- # remove feature prefix
- tmp="${tmp#feature-}"
-
- # get feature name by removing the version portion
- name="${tmp%%-[0-9]*}"
-
- # extract version portion of name
- version="${tmp#${name}-}"
-
- # determine status
- status=disabled
- if [[ -e "${LIB}/${jar}" ]] ; then
- status=enabled
- fi
- printf "${format}" "${name}" "${version}" "${status}"
- done
- echo
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- status --"
+ set -x
+ fi
+
+ local tmp name version status
+ local format="%-${nameLength}s %-${versionLength}s %s\n"
+
+ printf "${format}" "name" "version" "status"
+ printf "${format}" "----" "-------" "------"
+
+ for jar in ${featureJars} ; do
+ # get file name without 'jar' suffix
+ tmp="${jar%\.jar}"
+
+ # remove feature prefix
+ tmp="${tmp#feature-}"
+
+ # get feature name by removing the version portion
+ name="${tmp%%-[0-9]*}"
+
+ # extract version portion of name
+ version="${tmp#${name}-}"
+
+ # determine status
+ status=disabled
+ if [ -e "${LIB}/${jar}" ] ; then
+ status=enabled
+ fi
+ printf "${format}" "${name}" "${version}" "${status}"
+ done
+ echo
}
# ##########################################################
-# enableDepAnalysis (featureName):
+# enableDepAnalysis (featureName):
# reports on potential dependency conflicts
# featureName: name of the feature
# ##########################################################
function enableDepAnalysis ()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureDepJars featureDepJarPath depJarName multiVersionJars
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureDepJars=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
- for featureDepJarPath in ${featureDepJars}; do
- depJarName=$(basename "${featureDepJarPath}")
-
- # it could be a base jar
-
- if [[ -f "${LIB}"/"${depJarName}" ]]; then
- echo "warning: dependency ${depJarName} already in use"
- continue
- fi
-
- # it could be a link from another feature
-
- if [[ -L "${LIB}"/"${depJarName}" ]]; then
- continue
- fi
-
- # unadvisable if multiple versions exist but the base or
- # installed one wins.
-
- multiVersionJars=$(ls "${LIB}"/"${depJarName%%-[0-9]*.jar}"-*.jar 2> /dev/null)
- if [[ -n "${multiVersionJars}" ]]; then
- echo "warning: other version of library ${depJarName} present: ${multiVersionJars}"
- continue
- fi
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableDepAnalysis $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureDepJars featureDepJarPath depJarName multiVersionJars
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ fi
+
+ featureDepJars=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
+ for featureDepJarPath in ${featureDepJars}; do
+ depJarName=$(basename "${featureDepJarPath}")
+
+ # it could be a base jar
+
+ if [ -f "${LIB}"/"${depJarName}" ]; then
+ echo "warning: dependency ${depJarName} already in use"
+ continue
+ fi
+
+ # it could be a link from another feature
+
+ if [ -L "${LIB}"/"${depJarName}" ]; then
+ continue
+ fi
+
+ # unadvisable if multiple versions exist but the base or
+ # installed one wins.
+
+ multiVersionJars=$(ls "${LIB}"/"${depJarName%%-[0-9]*.jar}"-*.jar 2> /dev/null)
+ if [ -n "${multiVersionJars}" ]; then
+ echo "warning: other version of library ${depJarName} present: ${multiVersionJars}"
+ continue
+ fi
+ done
}
# ##########################################################
-# enableConfigAnalysis (featureName):
+# enableConfigAnalysis (featureName):
# reports on potential dependency conflicts
# featureName: name of the feature
# ##########################################################
function enableConfigAnalysis ()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureConfigs configPath configFileName
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureConfigs=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ 2> /dev/null)
- for configPath in ${featureConfigs}; do
- configFileName=$(basename "${configPath}")
- if [[ -e "${CONFIG}"/"${configFileName}" ]]; then
- echo "error: a config file of the same name is already in the base installation: ${configFileName}"
- return 2
- fi
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableConfigAnalysis $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureConfigs configPath configFileName
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureConfigs=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ 2> /dev/null)
+ for configPath in ${featureConfigs}; do
+ configFileName=$(basename "${configPath}")
+ if [ -e "${CONFIG}"/"${configFileName}" ]; then
+ echo "error: a config file of the same name is already in the base installation: ${configFileName}"
+ return 2
+ fi
+ done
}
# ##########################################################
@@ -362,232 +362,230 @@ function enableConfigAnalysis ()
# ##########################################################
function enableBinAnalysis ()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureBins binPath binFileName
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureBins=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ 2> /dev/null)
- for binPath in ${featureBins}; do
- binFileName=$(basename "${binPath}")
- if [[ -e "${CONFIG}"/"${binFileName}" ]]; then
- echo "error: a bin file of the same name is already in the base installation: ${binFileName}"
- return 2
- fi
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableBinAnalysis $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureBins binPath binFileName
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureBins=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ 2> /dev/null)
+ for binPath in ${featureBins}; do
+ binFileName=$(basename "${binPath}")
+ if [ -e "${CONFIG}"/"${binFileName}" ]; then
+ echo "error: a bin file of the same name is already in the base installation: ${binFileName}"
+ return 2
+ fi
+ done
}
# ##########################################################
-# enableDbAnalysis (featureName):
+# enableDbAnalysis (featureName):
# reports on potential db access problems
# featureName: name of the feature
# ##########################################################
function enableDbAnalysis()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureSqls
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureSqls=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)
- if [[ -z ${featureSqls} ]]; then
- return 0
- fi
-
- source "${POLICY_HOME}"/etc/profile.d/env.sh
- if [[ -z ${SQL_HOST} ]] || [[ -z ${SQL_USER} ]] || [[ -z ${SQL_PASSWORD} ]]; then
- echo "warning: DB server is not configured"
- fi
-
- return 0
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableDbAnalysis $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureSqls
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureSqls=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)
+ if [ -z "${featureSqls}" ]; then
+ return 0
+ fi
+
+ source "${POLICY_HOME}"/etc/profile.d/env.sh
+ if [ -z "${SQL_HOST}" ] || [ -z "${SQL_USER}" ] || [ -z "${SQL_PASSWORD}" ]; then
+ echo "warning: DB server is not configured"
+ fi
+
+ return 0
}
# ##########################################################
-# enableFeatureDeps(featureName):
+# enableFeatureDeps(featureName):
# enables feature dependencies
# featureName: name of the feature
# ##########################################################
function enableFeatureDeps()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureDeps featureDepPath depJarName
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
- for featureDepPath in ${featureDeps}; do
- depJarName=$(basename "${featureDepPath}")
- if [[ ! -f "${LIB}"/"${depJarName}" ]]; then
- ln -s -f "${featureDepPath}" "${LIB}/"
- fi
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableFeatureDeps $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureDeps featureDepPath depJarName
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
+ for featureDepPath in ${featureDeps}; do
+ depJarName=$(basename "${featureDepPath}")
+ if [ ! -f "${LIB}"/"${depJarName}" ]; then
+ ln -s -f "${featureDepPath}" "${LIB}/"
+ fi
+ done
}
# ##########################################################
-# enableFeatureConfig(featureName):
+# enableFeatureConfig(featureName):
# enables feature configuration
# featureName: name of the feature
# ##########################################################
function enableFeatureConfig()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureConfigs featureConfigPath
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null)
- for featureConfigPath in ${featureConfigs}; do
- ln -s -f "${featureConfigPath}" "${CONFIG}/"
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableFeatureConfig $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureConfigs featureConfigPath
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null)
+ for featureConfigPath in ${featureConfigs}; do
+ ln -s -f "${featureConfigPath}" "${CONFIG}/"
+ done
}
# ##########################################################
-# enableFeatureBin(featureName):
-# enables feature binaries
+# enableFeatureBin(featureName): enables feature binaries
# featureName: name of the feature
# ##########################################################
function enableFeatureBin()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureBins featureBinPath
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null)
- for featureBinPath in ${featureBins}; do
- chmod u+x "${featureBinPath}"
- ln -s -f "${featureBinPath}" "${BIN}/"
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableFeatureBin $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureBins featureBinPath
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null)
+ for featureBinPath in ${featureBins}; do
+ chmod u+x "${featureBinPath}"
+ ln -s -f "${featureBinPath}" "${BIN}/"
+ done
}
# ##########################################################
-# enableFeatureDbSchema(featureName):
+# enableFeatureDbSchema(featureName):
# enables feature DB Schema configuration
# featureName: name of the feature
# ##########################################################
function enableFeatureDbSchema()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureDbPath="$2"
- local schemaName="$3"
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- if [[ -z ${featureDbPath} ]]; then
- echo "warning: ${featureName} contains no DB path"
- return 2
- fi
-
- if [[ -z ${schemaName} ]]; then
- echo "warning: feature ${featureName} contains no schema name"
- return 3
- fi
-
- rc=0
- sqlUpgradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)
- for sqlUpgradeScript in ${sqlUpgradeScripts}; do
- if [[ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]]; then
- mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null
- fi
- ln -s -f "${sqlUpgradeScript}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/
- done
-
- sqlDowngradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${DOWNGRADE_SQL_SUFFIX} 2> /dev/null)
- for sqlDowngradeScript in ${sqlDowngradeScripts}; do
- if [[ -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]]; then
- sqlName=$(basename "${sqlDowngradeScript}")
- rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null
- else
- echo "warning: feature ${featureName} only contains downgrade scripts"
- rc=4
- break
- fi
- done
-
- if [[ -n ${sqlUpgradeScripts} || -n ${sqlDowngradeScripts} ]]; then
- DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok
- fi
-
- return ${rc}
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableFeatureDbSchema $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureDbPath="$2"
+ local schemaName="$3"
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ if [ -z "${featureDbPath}" ]; then
+ echo "warning: ${featureName} contains no DB path"
+ return 2
+ fi
+
+ if [ -z "${schemaName}" ]; then
+ echo "warning: feature ${featureName} contains no schema name"
+ return 3
+ fi
+
+ rc=0
+ sqlUpgradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)
+ for sqlUpgradeScript in ${sqlUpgradeScripts}; do
+ if [ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then
+ mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null
+ fi
+ ln -s -f "${sqlUpgradeScript}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/
+ done
+
+ sqlDowngradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${DOWNGRADE_SQL_SUFFIX} 2> /dev/null)
+ for sqlDowngradeScript in ${sqlDowngradeScripts}; do
+ if [ -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then
+ sqlName=$(basename "${sqlDowngradeScript}")
+ rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null
+ else
+ echo "warning: feature ${featureName} only contains downgrade scripts"
+ rc=4
+ break
+ fi
+ done
+
+ if [ -n "${sqlUpgradeScripts}" ] || [ -n "${sqlDowngradeScripts}" ]; then
+ DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok
+ fi
+
+ return ${rc}
}
# ##########################################################
-# enableFeatureDb(featureName):
+# enableFeatureDb(featureName):
# enables DB feature configuration
# featureName: name of the feature
# ##########################################################
function enableFeatureDb()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureDbs featureDbPath schemaName sqls
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null)
- for featureDbPath in ${featureDbs}; do
- sqls=$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*.sql 2> /dev/null)
- if [[ -z ${sqls} ]]; then
- continue
- fi
- schemaName=$(basename "${featureDbPath%/}")
- enableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}"
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableFeatureDb $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureDbs featureDbPath schemaName sqls
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null)
+ for featureDbPath in ${featureDbs}; do
+ sqls=$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*.sql 2> /dev/null)
+ if [ -z "${sqls}" ]; then
+ continue
+ fi
+ schemaName=$(basename "${featureDbPath%/}")
+ enableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}"
+ done
}
# ##########################################################
@@ -597,61 +595,59 @@ function enableFeatureDb()
# ##########################################################
function enableFeatureArtifacts()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local artifacts
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- artifacts=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_ARTIFACTS}"/* 2> /dev/null)
- for artifactPath in ${artifacts}; do
- deploy-artifact -l -a "${artifactPath}"
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- enableFeatureArtifacts $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local artifacts
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ artifacts=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_ARTIFACTS}"/* 2> /dev/null)
+ for artifactPath in ${artifacts}; do
+ deploy-artifact -l -a "${artifactPath}"
+ done
}
# ##########################################################
-# customize(featureName):
-# executes customized script for an operation.
+# customize(featureName):
+# executes customized script for an operation.
#
# featureName - feature name
-# operation - operation, ie.
+# operation - operation, ie.
# 'enable', 'disable', 'install', or 'uninstall'
# ##########################################################
function customOpScript()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local operation="$2"
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- if [[ -z ${operation} ]]; then
- echo "warning: ${featureName} : a custom operation script must be provided"
- return 1
- fi
-
- local customScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/"${operation}"
- if [[ -f ${customScript} ]]; then
- (
- cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"
- chmod u+x "${customScript}"
- ./"$(basename "${customScript}")"
- )
- fi
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- customOpScript $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local operation="$2"
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ if [ -z "${operation}" ]; then
+ echo "warning: ${featureName} : a custom operation script must be provided"
+ return 1
+ fi
+
+ local customScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/"${operation}"
+ if [ -f "${customScript}" ]; then
+ cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"
+ chmod u+x "${customScript}"
+ ./"$(basename "${customScript}")"
+ fi
}
# ##########################################################
@@ -661,157 +657,158 @@ function customOpScript()
# ##########################################################
function enableFeature()
{
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureJar="$2"
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- if [[ -z ${featureJar} ]]; then
- echo "warning: no feature jar"
- return 2
- fi
-
- if ! enableDepAnalysis "${featureName}"; then
- return "$?"
- fi
-
- if ! enableConfigAnalysis "${featureName}"; then
- return "$?"
- fi
-
- if ! enableBinAnalysis "${featureName}"; then
- return "$?"
- fi
-
- if ! enableDbAnalysis "${featureName}"; then
- return "$?"
- fi
-
- # enable feature itself
-
- ln -s -f "${featureJar}" "${LIB}/"
-
- # enable dependent libraries if any
-
- enableFeatureDeps "${featureName}"
-
- # enable configuration
-
- enableFeatureConfig "${featureName}"
-
- # enable binaries
-
- enableFeatureBin "${featureName}"
-
- # enable db
-
- enableFeatureDb "${featureName}"
-
- # enable feature artifacts
-
- enableFeatureArtifacts "${featureName}"
-
- # run custom enable if any
-
- customOpScript "${featureName}" "enable"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- enableFeature $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureJar="$2"
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ if [ -z "${featureJar}" ]; then
+ echo "warning: no feature jar"
+ return 2
+ fi
+
+ if ! enableDepAnalysis "${featureName}"; then
+ return "$?"
+ fi
+
+ if ! enableConfigAnalysis "${featureName}"; then
+ return "$?"
+ fi
+
+ if ! enableBinAnalysis "${featureName}"; then
+ return "$?"
+ fi
+
+ if ! enableDbAnalysis "${featureName}"; then
+ return "$?"
+ fi
+
+ # enable feature itself
+
+ ln -s -f "${featureJar}" "${LIB}/"
+
+ # enable dependent libraries if any
+
+ enableFeatureDeps "${featureName}"
+
+ # enable configuration
+
+ enableFeatureConfig "${featureName}"
+
+ # enable binaries
+
+ enableFeatureBin "${featureName}"
+
+ # enable db
+
+ enableFeatureDb "${featureName}"
+
+ # enable feature artifacts
+
+ enableFeatureArtifacts "${featureName}"
+
+ # run custom enable if any
+
+ customOpScript "${featureName}" "enable"
}
# ##########################################################
-# disableFeatureDeps(featureName):
-# disables feature dependencies
+# disableFeatureDeps(featureName):
+# disables feature dependencies
# ##########################################################
function disableFeatureDeps()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local xDepsEnabledMap featureBaseDirs aFeatureDir aFeatureName
- local featureDeps aFeatureDep
- local depJarPath depJarName depJarRealPath
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- declare -A xDepsEnabledMap
-
- featureBaseDirs=$(ls -d "${FEATURES}"/*/ 2> /dev/null)
- for aFeatureDir in ${featureBaseDirs}; do
- aFeatureName=$(basename "${aFeatureDir}")
- if [[ "${aFeatureName}" == "${featureName}" ]]; then
- continue
- fi
-
- depJarPaths=$(ls "${aFeatureDir}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
- for depJarPath in ${depJarPaths}; do
- if [[ "$?" == 0 ]] ; then
- depJarName=$(basename "${depJarPath}")
- xDepsEnabledMap[${depJarName}]="${depJarPath}"
- fi
- done
- done
-
- if [[ ${DEBUG} == y ]]; then
- echo "${!xDepsEnabledMap[@]}"
- echo "${xDepsEnabledMap[@]}"
- fi
-
- featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
- for aFeatureDep in ${featureDeps}; do
- depJarName=$(basename "${aFeatureDep}")
- if [[ -L "${LIB}"/"${depJarName}" ]]; then
- depJarRealPath=$(readlink -f "${LIB}"/"${depJarName}")
- if [[ "${depJarRealPath}" == "${aFeatureDep}" ]]; then
- rm -f "${LIB}"/"${depJarName}"
-
- # case there were multiple features using this library
- # re-enable link fron an enabled feature
-
- if [[ -n ${xDepsEnabledMap[${depJarName}]} ]]; then
- ln -s -f "${xDepsEnabledMap[${depJarName}]}" "${LIB}/"
- fi
- fi
- fi
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- disableFeatureDeps $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local aDepsEnabledMap xDepsEnabledMap featureBaseDirs aFeatureDir aFeatureName
+ local featureDeps aFeatureDep
+ local depJarPath depJarName depJarRealPath
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureBaseDirs=$(ls -d "${FEATURES}"/*/ 2> /dev/null)
+ for aFeatureDir in ${featureBaseDirs}; do
+ aFeatureName=$(basename "${aFeatureDir}")
+ if [ "${aFeatureName}" = "${featureName}" ]; then
+ continue
+ fi
+
+ depJarPaths=$(ls "${aFeatureDir}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
+ for depJarPath in ${depJarPaths}; do
+ if [ "$?" = "0" ] ; then
+ depJarName=$(basename "${depJarPath}")
+ xDepsEnabledMap="${xDepsEnabledMap} ${depJarPath}"
+ fi
+ done
+ done
+
+ if [ "${DEBUG}" = "y" ]; then
+ echo "${xDepsEnabledMap}"
+ fi
+
+ featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null)
+ for aFeatureDep in ${featureDeps}; do
+ depJarName=$(basename "${aFeatureDep}")
+ #
+ # check if defJarName is a sym-link
+ #
+ if [ -L "${LIB}"/"${depJarName}" ]; then
+ depJarRealPath=$(readlink -f "${LIB}"/"${depJarName}")
+ if [ "${depJarRealPath}" = "${aFeatureDep}" ]; then
+ rm -f "${LIB}"/"${depJarName}"
+
+ # case there were multiple features using this library
+ # re-enable link fron an enabled feature
+ for aDepsEnabledMap in ${xDepsEnabledMap}; do
+ if [ $(basename "${aDepsEnabledMap}") = ${depJarName} ]; then
+ ln -s -f "${aDepsEnabledMap}" "${LIB}/"
+ fi
+ done
+ fi
+ fi
+ done
}
# ##########################################################
-# disableFeatureConfig(featureName):
+# disableFeatureConfig(featureName):
# disables feature configuration
# featureName: name of the feature
# ##########################################################
function disableFeatureConfig()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureConfigs featureConfigPath
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null)
- for featureConfigPath in ${featureConfigs}; do
- configFileName=$(basename "${featureConfigPath}")
- rm -f "${CONFIG}"/"${configFileName}" 2> /dev/null
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- disableFeatureConfig $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureConfigs featureConfigPath
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null)
+ for featureConfigPath in ${featureConfigs}; do
+ configFileName=$(basename "${featureConfigPath}")
+ rm -f "${CONFIG}"/"${configFileName}" 2> /dev/null
+ done
}
# ##########################################################
@@ -821,116 +818,115 @@ function disableFeatureConfig()
# ##########################################################
function disableFeatureBin()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureBins featureBinPath
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null)
- for featureBinPath in ${featureBins}; do
- binFileName=$(basename "${featureBinPath}")
- rm -f "${BIN}"/"${binFileName}" 2> /dev/null
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- disableFeatureBin $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureBins featureBinPath
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null)
+ for featureBinPath in ${featureBins}; do
+ binFileName=$(basename "${featureBinPath}")
+ rm -f "${BIN}"/"${binFileName}" 2> /dev/null
+ done
}
# ##########################################################
-# disableFeatureDbSchema(featureName, featureDbPath, schemaName):
-# disables feature db configuration for a schema
+# disableFeatureDbSchema(featureName, featureDbPath, schemaName):
+# disables feature db configuration for a schema
# featureName: name of the feature
# ##########################################################
function disableFeatureDbSchema()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1" featureDbPath="$2" schemaName="$3"
- local upgradeFeatureSqls downgradeFeatureSqls featureSql sqlDir sqlName schemaDir schemaName
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- if [[ -z ${featureDbPath} ]]; then
- echo "warning: ${featureName} contains no DB path"
- return 2
- fi
-
- if [[ -z ${schemaName} ]]; then
- echo "warning: feature ${featureName} contains no schema name"
- return 3
- fi
-
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- upgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${UPGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null)
- for featureSql in ${upgradeFeatureSqls}; do
- sqlName=$(basename "${featureSql}")
- sqlDir=$(dirname "${featureSql}")
- schemaDir=$(dirname "${sqlDir}")
- schemaName=$(basename "${schemaDir}")
- rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null
- done
-
- downgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${DOWNGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null)
- for featureSql in ${downgradeFeatureSqls}; do
- sqlName=$(basename "${featureSql}")
- sqlDir=$(dirname "${featureSql}")
- schemaDir=$(dirname "${sqlDir}")
- schemaName=$(basename "${schemaDir}")
- if [[ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]]; then
- mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null
- fi
- ln -s -f "${featureSql}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/
- done
-
- if [[ -n ${sqlUpgradeScripts} || -n ${sqlDowngradeScripts} ]]; then
- DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok
- fi
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- disableFeatureDbSchema $* --"
+ set -x
+ fi
+
+ local featureName="$1" featureDbPath="$2" schemaName="$3"
+ local upgradeFeatureSqls downgradeFeatureSqls featureSql sqlDir sqlName schemaDir schemaName
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ if [ -z "${featureDbPath}" ]; then
+ echo "warning: ${featureName} contains no DB path"
+ return 2
+ fi
+
+ if [ -z "${schemaName}" ]; then
+ echo "warning: feature ${featureName} contains no schema name"
+ return 3
+ fi
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ upgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${UPGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null)
+ for featureSql in ${upgradeFeatureSqls}; do
+ sqlName=$(basename "${featureSql}")
+ sqlDir=$(dirname "${featureSql}")
+ schemaDir=$(dirname "${sqlDir}")
+ schemaName=$(basename "${schemaDir}")
+ rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null
+ done
+
+ downgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${DOWNGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null)
+ for featureSql in ${downgradeFeatureSqls}; do
+ sqlName=$(basename "${featureSql}")
+ sqlDir=$(dirname "${featureSql}")
+ schemaDir=$(dirname "${sqlDir}")
+ schemaName=$(basename "${schemaDir}")
+ if [ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then
+ mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null
+ fi
+ ln -s -f "${featureSql}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/
+ done
+
+ if [ -n "${sqlUpgradeScripts}" ] || [ -n "${sqlDowngradeScripts}" ]; then
+ DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok
+ fi
}
# ##########################################################
-# disableFeatureDb(featureName):
-# disables feature db configuration
+# disableFeatureDb(featureName):
+# disables feature db configuration
# featureName: name of the feature
# ##########################################################
function disableFeatureDb()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureDbPath featureDbs schemaName
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null)
- for featureDbPath in ${featureDbs}; do
- if [[ -z "$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)" ]]; then
- continue
- fi
- schemaName=$(basename "${featureDbPath%/}")
- disableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}"
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- disableFeatureDb $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureDbPath featureDbs schemaName
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null)
+ for featureDbPath in ${featureDbs}; do
+ if [ -z "$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)" ]; then
+ continue
+ fi
+ schemaName=$(basename "${featureDbPath%/}")
+ disableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}"
+ done
}
# ##########################################################
@@ -939,44 +935,44 @@ function disableFeatureDb()
# ##########################################################
function disableFeature()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return
- fi
-
- # disable feature itself
-
- (
- cd "${LIB}"
- rm -f feature-"${featureName}"-[0-9]*.jar 2> /dev/null
- )
-
- # disable dependencies if any
-
- disableFeatureDeps "${featureName}"
-
- # disable configuration if any
-
- disableFeatureConfig "${featureName}"
-
- # disable binaries if any
-
- disableFeatureBin "${featureName}"
-
- # disable DB SQL scripts if any
-
- disableFeatureDb "${featureName}"
-
- # run custom disable if any
-
- customOpScript "${featureName}" "disable"
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- disableFeature $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return
+ fi
+
+ # disable feature itself
+
+ (
+ cd "${LIB}"
+ rm -f feature-"${featureName}"-[0-9]*.jar 2> /dev/null
+ )
+
+ # disable dependencies if any
+
+ disableFeatureDeps "${featureName}"
+
+ # disable configuration if any
+
+ disableFeatureConfig "${featureName}"
+
+ # disable binaries if any
+
+ disableFeatureBin "${featureName}"
+
+ # disable DB SQL scripts if any
+
+ disableFeatureDb "${featureName}"
+
+ # run custom disable if any
+
+ customOpScript "${featureName}" "disable"
}
############################################################
@@ -985,40 +981,40 @@ function disableFeature()
# This was copied from 'policy-drools/docker-install.sh'
# in the 'docker' repository, and modified where needed.
############################################################
-function configureFeature()
+function configureFeature()
{
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local envConfig=$1 featureRoot=$2
- local sedLine="sed -i"
- local sedFiles="" nonBinaryFiles sedFile name value
-
- while read line || [ -n "${line}" ]; do
- if [[ -n ${line} ]] && [[ ${line:0:1} != \# ]]; then
- name="${line%%=*}"
- value="${line#*=}"
- value=$(echo "${value}" | sed -e 's/[\/&]/\\&/g')
- if [[ -z ${name} ]] || [[ -z ${value} ]]; then
- echo "warning: ${line} missing name or value"
- fi
- sedLine+=" -e 's/\${{${name}}}/${value}/g' "
- fi
- done < "${envConfig}"
-
- nonBinaryFiles=$(find "${featureRoot}" -type f -exec grep -Iq . {} \; -print 2> /dev/null)
- for sedFile in ${nonBinaryFiles}; do
- if fgrep -l '${{' ${sedFile} > /dev/null 2>&1; then
- sedFiles+="${sedFile} "
- fi
- done
-
- if [[ -n ${sedFiles} ]]; then
- sedLine+=${sedFiles}
- eval "${sedLine}"
- fi
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- configureFeature $* --"
+ set -x
+ fi
+
+ local envConfig=$1 featureRoot=$2
+ local sedLine="sed -i"
+ local sedFiles="" nonBinaryFiles sedFile name value
+
+ while read line || [ -n "${line}" ]; do
+ if [ -n "${line}" ] && [ "${line:0:1}" != \# ]; then
+ name="${line%%=*}"
+ value="${line#*=}"
+ value=$(echo "${value}" | sed -e 's/[\/&]/\\&/g')
+ if [ -z "${name}" ] || [ -z "${value}" ]; then
+ echo "warning: ${line} missing name or value"
+ fi
+ sedLine+=" -e 's/\${{${name}}}/${value}/g' "
+ fi
+ done < "${envConfig}"
+
+ nonBinaryFiles=$(find "${featureRoot}" -type f -exec grep -Iq . {} \; -print 2> /dev/null)
+ for sedFile in ${nonBinaryFiles}; do
+ if fgrep -l '${{' ${sedFile} > /dev/null 2>&1; then
+ sedFiles+="${sedFile} "
+ fi
+ done
+
+ if [ -n "${sedFiles}" ]; then
+ sedLine+=${sedFiles}
+ eval "${sedLine}"
+ fi
}
############################################################
@@ -1029,121 +1025,100 @@ function configureFeature()
############################################################
function installFeatures
{
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local name featureConf feature dir conf
-
- if [[ -d "${FEATURES}" && -x "${FEATURES}" ]]; then
- SOURCE_DIR=$PWD
- for feature in "$@" ; do
- dir=
- if [[ "${feature}" == feature-*.zip ||
- "${feature}" == */feature-*.zip ]] ; then
- # the ZIP file is specified -- find the name
- name="${feature##*/}"
- name="${name#feature-}"
- name="${name%%-[0-9]*\.zip}"
-
- # if the ZIP file has a directory name component,
- # set 'dir' accordingly
- if [[ "${feature}" =~ / ]] ; then
- dir="${feature%/*}"
- fi
- else
- # Doesn't match the ZIP file name convention -- interpret
- # this as a feature name, and try to locate a matching ZIP
- # file. If there is more than one, choose the one with the
- # highest version number.
- name="${feature}"
- feature=$(ls -v feature-"${name}"-[0-9]*.zip 2>/dev/null|tail -1)
- fi
- if [[ ! -f "${feature}" ]] ; then
- # include the file name in the error message, unless we don't
- # have one -- in this case, use the feature name
- echo "error: feature file ${feature:-for ${name}} not found"
- continue
- fi
- if [[ -d "${FEATURES}/${name}" ]] ; then
- echo "error: feature ${name} has already been installed"
- continue
- fi
-
- # extract contents of ZIP file in to feature directory
- mkdir -p "${FEATURES}/${name}" > /dev/null 2>&1
- (cd "${FEATURES}/${name}"; jar xf "${SOURCE_DIR}"/"${feature}")
-
- # if there is a configuration file available,
- # use it to configure the feature
- featureConf="${dir:+$dir/}feature-${name}.conf"
- if [[ -r "${featureConf}" ]]; then
- configureFeature "${featureConf}" "${FEATURES}"/"${name}"
- cp "${featureConf}" "${POLICY_HOME}"/etc/profile.d
- echo "feature ${name} has been installed (configuration present)"
- else
- echo "feature ${name} has been installed (no configuration present)"
- fi
-
- customOpScript "${name}" "install"
- done
-
- # check the current directory and the 'config' directory for a
- # 'base.conf' file -- use the first one that is found
- for conf in base.conf ${POLICY_HOME}/config/base.conf ${POLICY_HOME}/etc/profile.d/base.conf; do
- if [[ -f "${conf}" ]] ; then
- echo "applying base configuration '${conf}' to features"
- configureFeature "${conf}" "${FEATURES}"
- break
- fi
- done
- else
- echo "error: aborting -- ${FEATURES} is not accessible"
- exit 1
- fi
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- installFeatures $* --"
+ set -x
+ fi
+
+ local name featureConf feature conf
+ if [ -d "${FEATURES}" ]; then
+ SOURCE_DIR=$PWD
+ for feature in "$@" ; do
+ name="${feature}"
+ feature=$(ls -v feature-"${name}"-[0-9]*.zip 2>/dev/null|tail -1)
+ if [ ! -f "${feature}" ] ; then
+ # include the file name in the error message, unless we don't
+ # have one -- in this case, use the feature name
+ echo "error: feature file ${feature:-for ${name}} not found"
+ continue
+ fi
+ if [ -d "${FEATURES}/${name}" ] ; then
+ echo "error: feature ${name} has already been installed"
+ continue
+ fi
+
+ # extract contents of ZIP file in to feature directory
+ mkdir -p "${FEATURES}/${name}" > /dev/null 2>&1
+ (cd "${FEATURES}/${name}"; jar xf "${SOURCE_DIR}"/"${feature}")
+
+ # if there is a configuration file available,
+ # use it to configure the feature
+ featureConf="${dir:+$dir/}feature-${name}.conf"
+ if [ -r "${featureConf}" ]; then
+ configureFeature "${featureConf}" "${FEATURES}"/"${name}"
+ cp "${featureConf}" "${POLICY_HOME}"/etc/profile.d
+ echo "feature ${name} has been installed (configuration present)"
+ else
+ echo "feature ${name} has been installed (no configuration present)"
+ fi
+
+ customOpScript "${name}" "install"
+ done
+
+ # check the current directory and the 'config' directory for a
+ # 'base.conf' file -- use the first one that is found
+ for conf in base.conf ${POLICY_HOME}/config/base.conf ${POLICY_HOME}/etc/profile.d/base.conf; do
+ if [ -f "${conf}" ] ; then
+ echo "applying base configuration '${conf}' to features"
+ configureFeature "${conf}" "${FEATURES}"
+ break
+ fi
+ done
+ else
+ echo "error: aborting -- ${FEATURES} is not accessible"
+ exit 1
+ fi
}
# ##########################################################
-# uninstallFeatureDb(featureName):
-# uninstalls the feature db configuration
+# uninstallFeatureDb(featureName):
+# uninstalls the feature db configuration
# featureName: name of the feature
# ##########################################################
function uninstallFeatureDb()
{
- if [[ ${DEBUG} == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
- local featureSqls sqlDir sqlName schemaDir schemaName schemaNames leftSqls
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return 1
- fi
-
- featureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*.sql -type f -maxdepth 1 2> /dev/null)
- for featureSql in ${featureSqls}; do
- sqlName=$(basename "${featureSql}")
- sqlDir=$(dirname "${featureSql}")
- schemaDir=$(dirname "${sqlDir}")
- schemaName=$(basename "${schemaDir}")
- schemaNames+=${schemaName}
- rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null
- done
-
- for schemaName in ${schemaNames};
- do
- leftSqls=$(ls "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/*.sql 2> /dev/null)
- if [[ -z ${leftSqls} ]]; then
- if ! DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok; then
- echo -n "warning: ${featureName}: ${schemaName}: database data is leftover. "
- echo -n "Consider cleaning left over data with 'db-migrator'."
- fi
- fi
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- uninstallFeatureDb $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+ local featureSqls sqlDir sqlName schemaDir schemaName schemaNames leftSqls
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return 1
+ fi
+
+ featureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*.sql -type f -maxdepth 1 2> /dev/null)
+ for featureSql in ${featureSqls}; do
+ sqlName=$(basename "${featureSql}")
+ sqlDir=$(dirname "${featureSql}")
+ schemaDir=$(dirname "${sqlDir}")
+ schemaName=$(basename "${schemaDir}")
+ schemaNames="${schemaNames} ${schemaName}"
+ rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null
+ done
+ for schemaName in ${schemaNames};
+ do
+ leftSqls=$(ls "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/*.sql 2> /dev/null)
+ if [ -n "${leftSqls}" ]; then
+ if ! DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok; then
+ echo -n "warning: ${featureName}: ${schemaName}: database data is leftover. "
+ echo -n "Consider cleaning left over data with 'db-migrator'."
+ fi
+ fi
+ done
}
############################################################
@@ -1151,25 +1126,24 @@ function uninstallFeatureDb()
############################################################
function uninstallFeature
{
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} $* --"
- set -x
- fi
-
- local featureName="$1"
-
- if [[ -z ${featureName} ]]; then
- echo "warning: no feature name"
- return
- fi
-
- disableFeature "${featureName}"
- uninstallFeatureDb "${featureName}"
- customOpScript "${featureName}" "uninstall"
-
- if [[ -n ${FEATURES} && -n ${featureName} ]]; then
- rm -rf "${FEATURES:-???}/${featureName}"
- fi
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- uninstallFeature $* --"
+ set -x
+ fi
+
+ local featureName="$1"
+
+ if [ -z "${featureName}" ]; then
+ echo "warning: no feature name"
+ return
+ fi
+ disableFeature "${featureName}"
+ uninstallFeatureDb "${featureName}"
+ customOpScript "${featureName}" "uninstall"
+
+ if [ -n "${FEATURES}" ] && [ -n "${featureName}" ]; then
+ rm -rf "${FEATURES:-???}/${featureName}"
+ fi
}
############################################################
@@ -1177,120 +1151,129 @@ function uninstallFeature
############################################################
function uninstallFeatures
{
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
- set -x
- fi
-
- local name
- local allFeatures=$'\n'$(cd ${FEATURES};ls)$'\n'
- for name in "$@" ; do
- # the following check takes care of potentially troublesome names
- # like '.', '..', and names containing '/'
- if [[ "${allFeatures}" =~ $'\n'${name}$'\n' ]] ; then
- uninstallFeature "${name}"
- else
- echo "feature ${name} not found"
- fi
- done
+ if [ "${DEBUG}" = "y" ]; then
+ echo "-- uninstallFeatures --"
+ set -x
+ fi
+
+ local name
+ local allFeatures=$(cd ${FEATURES};ls)
+ local aFeature
+ local flag
+ for name in "$@" ; do
+ flag=false
+ # the following check takes care of potentially troublesome names
+ # like '.', '..', and names containing '/'
+ for aFeature in ${allFeatures};
+ do
+ if [ "${aFeature}" = "${name}" ] ; then
+ uninstallFeature "${name}"
+ echo "feature ${name} uninstalled"
+ flag=true
+ fi
+ done
+ if ! $flag; then
+ echo "error: feature ${name} not found"
+ fi
+ done
}
case "$1" in
- status)
- {
- # dump out status information
- status
- };;
-
- enable)
- {
- if [[ -f "${POLICY_HOME}"/PID ]]; then
- echo "error: enable: not allowed when policy is running .."
- echo
- status
- exit 10
- fi
-
- # enable the specified options
- shift
- match=
- for name in "$@" ; do
- # look for matches - 'file' has the full path name
- file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null)
- if [[ "$?" != 0 ]] ; then
- # no matching file
- echo "${name}: no such option"
- else
- # make sure there is only one feature jar
- countFeatureJars=$(echo "${file}" | wc -w)
- if [[ ${countFeatureJars} != 1 ]]; then
- echo "warning: skipping ${name}, ${countFeatureJars} feature libraries found"
- continue
- fi
-
- # found a match (handle multiple matches, just in case)
- match=true
-
- enableFeature "${name}" "${file}"
- fi
- done
- if [[ "${match}" ]] ; then
- echo
- status
- fi
- };;
-
- disable)
- {
- if [[ -f "${POLICY_HOME}"/PID ]]; then
- echo "error: disable: not allowed when policy is running .."
- echo
- status
- exit 11
- fi
-
- # disable the specified options
- shift
- match=
- for name in "$@" ; do
- # look for matches -- 'file' has the last segment of the path name
- file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null)
- if [[ "$?" != 0 ]] ; then
- echo "${name}: no such option"
- else
- # found a match (handle multiple matches, just in case)
- match=true
-
- disableFeature "${name}"
- fi
- done
- if [[ "${match}" ]] ; then
- echo
- status
- fi
- };;
-
- install)
- {
- shift
- installFeatures "$@"
- };;
-
- uninstall)
- {
- if [[ -f "${POLICY_HOME}"/PID ]]; then
- echo "error: uninstall: not allowed when policy is running .."
- echo
- status
- exit 12
- fi
- shift
- uninstallFeatures "$@"
- };;
-
- *)
- {
- usage
- };;
+ status)
+ {
+ # dump out status information
+ status
+ };;
+
+ enable)
+ {
+ if [ -f "${POLICY_HOME}"/PID ]; then
+ echo "error: enable: not allowed when policy is running .."
+ echo
+ status
+ exit 10
+ fi
+
+ # enable the specified options
+ shift
+ match=
+ for name in "$@" ; do
+ # look for matches - 'file' has the full path name
+ file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null)
+ if [ "$?" != "0" ] ; then
+ # no matching file
+ echo "enable feature: ${name} failed"
+ else
+ # make sure there is only one feature jar
+ countFeatureJars=$(echo "${file}" | wc -w)
+ if [ ${countFeatureJars} -ne 1 ]; then
+ echo "warning: skipping ${name}, ${countFeatureJars} feature libraries found"
+ continue
+ fi
+
+ # found a match (handle multiple matches, just in case)
+ match=true
+
+ enableFeature "${name}" "${file}"
+ fi
+ done
+ if [ "${match}" ] ; then
+ echo
+ status
+ fi
+ };;
+
+ disable)
+ {
+ if [ -f "${POLICY_HOME}"/PID ]; then
+ echo "error: disable: not allowed when policy is running .."
+ echo
+ status
+ exit 11
+ fi
+
+ # disable the specified options
+ shift
+ match=
+ for name in "$@" ; do
+ # look for matches -- 'file' has the last segment of the path name
+ file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null)
+ if [ "$?" != "0" ] ; then
+ echo "${name}: no such option"
+ else
+ # found a match (handle multiple matches, just in case)
+ match=true
+
+ disableFeature "${name}"
+ fi
+ done
+ if [ "${match}" ] ; then
+ echo
+ status
+ fi
+ };;
+
+ install)
+ {
+ shift
+ installFeatures "$@"
+ };;
+
+ uninstall)
+ {
+ if [ -f "${POLICY_HOME}"/PID ]; then
+ echo "error: uninstall: not allowed when policy is running .."
+ echo
+ status
+ exit 12
+ fi
+ shift
+ uninstallFeatures "$@"
+ };;
+
+ *)
+ {
+ usage
+ };;
esac
exit
diff --git a/policy-management/src/main/server-gen/bin/pdpd-configuration b/policy-management/src/main/server-gen/bin/pdpd-configuration
index fc822e18..a704a577 100644
--- a/policy-management/src/main/server-gen/bin/pdpd-configuration
+++ b/policy-management/src/main/server-gen/bin/pdpd-configuration
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -8,9 +8,9 @@
# 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.
@@ -21,112 +21,111 @@
source ${POLICY_HOME}/etc/profile.d/env.sh
function usage() {
- echo -n "Usage: $(basename $0) "
- echo -n "[(-d|--debug)] "
- echo -n "(-h|--host) <bus-host> "
- echo -n "[(-p|--port) <bus-port>] "
- echo -n "[(-k|--key) <api-key>] "
- echo -n "[(-s|--secret) <api-secret>] "
- echo -n "[(-r|--request-id) <request-id>] "
- echo -n "(-c|--controller-name) <controller-name> "
- echo -n "(-o|--operation) <create|update|lock|unlock> "
- echo -n "[(-g|--group-id) <group-id> "
- echo -n "(-a|--artifact-id) <artifact-id> "
- echo -n "(-v|--version) <version>] "
- echo -n "[(-t|--topic) <topic>] "
- echo ""
+ echo -n "Usage: $(basename $0) "
+ echo -n "[(-d|--debug)] "
+ echo -n "(-h|--host) <bus-host> "
+ echo -n "[(-p|--port) <bus-port>] "
+ echo -n "[(-k|--key) <api-key>] "
+ echo -n "[(-s|--secret) <api-secret>] "
+ echo -n "[(-r|--request-id) <request-id>] "
+ echo -n "(-c|--controller-name) <controller-name> "
+ echo -n "(-o|--operation) <create|update|lock|unlock> "
+ echo -n "[(-g|--group-id) <group-id> "
+ echo -n "(-a|--artifact-id) <artifact-id> "
+ echo -n "(-v|--version) <version>] "
+ echo -n "[(-t|--topic) <topic>] "
+ echo ""
}
BUS_PORT=3904
-ENTITY=controller
REQUEST_ID="7f5474ca-16a9-42ac-abc0-d86f62296fbc"
TOPIC="PDPD-CONFIGURATION"
# command line options parsing
-until [[ -z "$1" ]]; do
- case $1 in
- -d|--debug) set -x
- ;;
- -h|--host) shift
- BUS_HOST=$1
- ;;
- -p|--port) shift
- BUS_PORT=$1
- ;;
- -r|--request-id) shift
- REQUEST_ID=$1
- ;;
- -k|--key) shift
- API_KEY=$1
- ;;
- -s|--secret) shift
- API_SECRET=$1
- ;;
- -c|--controller-name) shift
- CONTROLLER_NAME=$1
- ;;
- -o|--operation) shift
- OPERATION=$1
- ;;
- -g|--group-id) shift
- GROUP_ID=$1
- ;;
- -a|--artifact-id) shift
- ARTIFACT_ID=$1
- ;;
- -v|--version) shift
- VERSION=$1
- ;;
- -t|--topic) shift
- TOPIC=$1
- ;;
- *) usage
- exit 1
- ;;
- esac
- shift
+until [ -z "$1" ]; do
+ case $1 in
+ -d|--debug) set -x
+ ;;
+ -h|--host) shift
+ BUS_HOST=$1
+ ;;
+ -p|--port) shift
+ BUS_PORT=$1
+ ;;
+ -r|--request-id) shift
+ REQUEST_ID=$1
+ ;;
+ -k|--key) shift
+ API_KEY=$1
+ ;;
+ -s|--secret) shift
+ API_SECRET=$1
+ ;;
+ -c|--controller-name) shift
+ CONTROLLER_NAME=$1
+ ;;
+ -o|--operation) shift
+ OPERATION=$1
+ ;;
+ -g|--group-id) shift
+ GROUP_ID=$1
+ ;;
+ -a|--artifact-id) shift
+ ARTIFACT_ID=$1
+ ;;
+ -v|--version) shift
+ VERSION=$1
+ ;;
+ -t|--topic) shift
+ TOPIC=$1
+ ;;
+ *) usage
+ exit 1
+ ;;
+ esac
+ shift
done
-if [[ -z ${BUS_HOST} ]]; then
- echo "An UEB/DMAAP server must be provided."
- echo
- usage
- exit 1
+if [ -z "${BUS_HOST}" ]; then
+ echo "An UEB/DMAAP server must be provided."
+ echo
+ usage
+ exit 1
fi
-if [[ -z ${CONTROLLER_NAME} ]]; then
- echo "The controller-name must be provided."
- usage
- exit 2
+if [ -z "${CONTROLLER_NAME}" ]; then
+ echo "The controller-name must be provided."
+ usage
+ exit 2
fi
-if [[ -z ${OPERATION} ]]; then
- echo "The operation must be provided: create|update|lock|unlock"
- usage
- exit 3
+if [ -z "${OPERATION}" ]; then
+ echo "The operation must be provided: create|update|lock|unlock"
+ usage
+ exit 3
fi
-if [[ ${OPERATION} == "create" ]] || [[ ${OPERATION} == "update" ]]; then
- if [[ -z ${GROUP_ID} ]]; then
- echo "The maven group id must be provided when operation is create|update"
- usage
- exit 4
- fi
-
- if [[ -z ${ARTIFACT_ID} ]]; then
- echo "The maven artifact id must be provided when operation is create|update"
- usage
- exit 5
- fi
-
- if [[ -z ${VERSION} ]]; then
- echo "The maven version must be provided when operation is create|update"
- usage
- exit 6
- fi
+if [ "${OPERATION}" = "create" ] || [ "${OPERATION}" = "update" ]; then
+ if [ -z "${GROUP_ID}" ]; then
+ echo "The maven group id must be provided when operation is create|update"
+ usage
+ exit 4
+ fi
+
+ if [ -z "${ARTIFACT_ID}" ]; then
+ echo "The maven artifact id must be provided when operation is create|update"
+ usage
+ exit 5
+ fi
+
+ if [ -z "${VERSION}" ]; then
+ echo "The maven version must be provided when operation is create|update"
+ usage
+ exit 6
+ fi
fi
-UPDATE_BODY=$(< <(cat <<EOF
+UPDATE_BODY=$(cat <<EOF
{
"requestID": "${REQUEST_ID}",
"entity": "controller",
@@ -140,11 +139,10 @@ UPDATE_BODY=$(< <(cat <<EOF
"operation": "${OPERATION}"
}]
}
-
EOF
-))
+)
-LOCK_BODY=$(< <(cat <<EOF
+LOCK_BODY=$(cat <<EOF
{
"requestID": "${REQUEST_ID}",
"entity": "controller",
@@ -155,46 +153,46 @@ LOCK_BODY=$(< <(cat <<EOF
}
EOF
-))
+)
unset http_proxy
-if [[ ${OPERATION} == "lock" ]] || [[ ${OPERATION} == "unlock" ]]; then
- if [[ -n ${API_KEY} ]]; then
- DATE=$(date)
- DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
- curl --silent -X POST \
- --header "Accept:" \
- --header "X-CambriaDate: ${DATE}" \
- --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
- --header "Content-Type: application/json" \
- --data "${LOCK_BODY}" \
- http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
- else
- curl --silent -X POST \
- --header "Accept:" \
- --header "Content-Type: application/json" \
- --data "${LOCK_BODY}" \
- http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
- fi
+if [ "${OPERATION}" = "lock" ] || [ "${OPERATION}" = "unlock" ]; then
+ if [ -n "${API_KEY}" ]; then
+ DATE=$(date)
+ DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
+ curl --silent -X POST \
+ --header "Accept:" \
+ --header "X-CambriaDate: ${DATE}" \
+ --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
+ --header "Content-Type: application/json" \
+ --data "${LOCK_BODY}" \
+ http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
+ else
+ curl --silent -X POST \
+ --header "Accept:" \
+ --header "Content-Type: application/json" \
+ --data "${LOCK_BODY}" \
+ http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
+ fi
fi
-if [[ ${OPERATION} == "create" ]] || [[ ${OPERATION} == "update" ]]; then
- if [[ -n ${API_KEY} ]]; then
- DATE=$(date)
- DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
- curl --silent -X POST \
- --header "Accept:" \
- --header "X-CambriaDate: ${DATE}" \
- --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
- --header "Content-Type: application/json" \
- --data "${UPDATE_BODY}" \
- http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
- else
- curl --silent -X POST \
- --header "Accept:" \
- --header "Content-Type: application/json" \
- --data "${UPDATE_BODY}" \
- http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
- fi
+if [ "${OPERATION}" = "create" ] || [ "${OPERATION}" = "update" ]; then
+ if [ -n "${API_KEY}" ]; then
+ DATE=$(date)
+ DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64)
+ curl --silent -X POST \
+ --header "Accept:" \
+ --header "X-CambriaDate: ${DATE}" \
+ --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \
+ --header "Content-Type: application/json" \
+ --data "${UPDATE_BODY}" \
+ http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
+ else
+ curl --silent -X POST \
+ --header "Accept:" \
+ --header "Content-Type: application/json" \
+ --data "${UPDATE_BODY}" \
+ http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC}
+ fi
fi
diff --git a/policy-management/src/main/server-gen/bin/policy-management-controller b/policy-management/src/main/server-gen/bin/policy-management-controller
index 1d9633bc..3d6fb190 100644
--- a/policy-management/src/main/server-gen/bin/policy-management-controller
+++ b/policy-management/src/main/server-gen/bin/policy-management-controller
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP POLICY
@@ -25,13 +25,13 @@ PNAME=policy-management
CLASS=org.onap.policy.drools.system.Main
function start() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- start --"
set -x
fi
um_start
- if [[ ${RETVAL} != 0 ]]; then
+ if [ $RETVAL -ne 0 ]; then
update_monitor off
else
update_monitor on
@@ -39,8 +39,8 @@ function start() {
}
function preRunning() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- preRunning --"
set -x
fi
@@ -51,25 +51,24 @@ function preRunning() {
source ${POLICY_HOME}/etc/profile.d/env.sh
${POLICY_HOME}/bin/configure-maven
- JVM_OPTS=(${JVM_OPTIONS})
# If 'system.properties' exists, convert it into "-D" JVM arguments.
# Note that the following also handles property values with spaces.
- IFS=$'\n'
- systemProperties=($(
- if [[ -f $_DIR/config/system.properties ]]; then
+
+ systemProperties=$(
+ if [ -f "$_DIR/config/system.properties" ]; then
sed -n -e 's/^[ \t]*\([^ \t#]*\)[ \t]*=[ \t]*\(.*\)$/-D\1=\2/p' \
$_DIR/config/system.properties
fi
- ))
+ )
cd $_DIR
}
function exec_start() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- exec_start --"
set -x
fi
@@ -80,13 +79,18 @@ function exec_start() {
fi
preRunning
- exec $JAVA_HOME/bin/java "${JVM_OPTS[@]}" -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS
+ exec $JAVA_HOME/bin/java ${JVM_OPTIONS} -cp $_DIR/config:$_DIR/lib:$CP ${systemProperties} "$@" $CLASS
+}
+
+# adding timestamp for stdout and stderr
+function timestamp () {
+ exec awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'
}
# unmonitored start, does not change monitor status (immutable)
function um_start() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- um_start --"
set -x
fi
@@ -104,15 +108,8 @@ function um_start() {
if [ -e $_LOGS/$PNAME.err ]; then mv $_LOGS/$PNAME.err $_LOGS/$PNAME.err.1; fi
(
- if [[ "${cfg}" != "" ]]; then
- # need to make sure that we don't pass the lock file descriptor
- # to subprocesses
- exec {cfg}>&-
- fi
- nohup $JAVA_HOME/bin/java "${JVM_OPTS[@]}" -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS > >(while read line; do echo "$(date): ${line}"; done >$_LOGS/$PNAME.out) 2> >(while read line; do echo "$(date): ${line}"; done >$_LOGS/$PNAME.err) &
-
- _PID=$!
- echo $_PID >$_PIDFILE
+ exec 200>&-
+ ( ( nohup $JAVA_HOME/bin/java ${JVM_OPTIONS} -cp $_DIR/config:$_DIR/lib:$CP ${systemProperties} "$@" $CLASS ) | timestamp > $_LOGS/$PNAME.out ) 2>&1 | timestamp > $_LOGS/$PNAME.err &
)
sleep 5
status
@@ -127,8 +124,8 @@ function um_start() {
}
function stop() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- stop --"
set -x
fi
@@ -138,8 +135,8 @@ function stop() {
# unmonitored stop, does not change monitor status (immutable)
function um_stop() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- um_stop --"
set -x
fi
@@ -148,7 +145,7 @@ function um_stop() {
echo $_STATUS
remove_pid_file
else
- if [[ -n ${TELEMETRY_PASSWORD} ]]; then
+ if [ -n "${TELEMETRY_PASSWORD}" ]; then
http_proxy= timeout 10 curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X DELETE https://localhost:${TELEMETRY_PORT}/policy/pdp/engine -o /dev/null
else
http_proxy= timeout 10 curl -k --silent -X DELETE https://localhost:${TELEMETRY_PORT}/policy/pdp/engine -o /dev/null
@@ -174,15 +171,15 @@ function um_stop() {
}
function status() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- status --"
set -x
fi
if [ -f "${_PIDFILE}" ]; then
_PID=$(cat "${_PIDFILE}")
check_status_of_pid "$_PID"
- elif [[ ${POLICY_DOCKER} == true ]] && _PID=$(pidof -s java); then
+ elif [ ${POLICY_DOCKER} ] && _PID=$(pidof -s java); then
echo "${_PID}" > ${_PIDFILE}
check_status_of_pid "$_PID"
else
@@ -190,7 +187,7 @@ function status() {
_RUNNING=0
fi
- if [[ $_RUNNING == 1 ]]; then
+ if [ "$_RUNNING" = "1" ]; then
RETVAL=0
else
RETVAL=1
@@ -198,8 +195,8 @@ function status() {
}
function check_status_of_pid() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- check_status_of_pid --"
set -x
fi
@@ -213,8 +210,8 @@ function check_status_of_pid() {
}
function remove_pid_file() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- remove_pid_file --"
set -x
fi
@@ -224,13 +221,13 @@ function remove_pid_file() {
}
function update_monitor() {
- if [[ $DEBUG == y ]]; then
- echo "-- ${FUNCNAME[0]} --"
+ if [ "$DEBUG" = "y" ]; then
+ echo "-- update_monitor --"
set -x
fi
STATUS=$1
- if [[ -f ${POLICY_HOME}/etc/monitor/monitor.cfg ]]; then
+ if [ -f "${POLICY_HOME}"/etc/monitor/monitor.cfg ]; then
/bin/sed -i.bak \
-e "s/^${CONTROLLER}=.*/${CONTROLLER}=${STATUS}/g" \
${POLICY_HOME}/etc/monitor/monitor.cfg
@@ -239,7 +236,7 @@ function update_monitor() {
# main
-if [[ ${DEBUG} == y ]]; then
+if [ "${DEBUG}" = "y" ]; then
echo "-- $0 $* --"
set -x
fi
@@ -247,7 +244,7 @@ fi
_DIR=${POLICY_HOME}
_LOGS=${POLICY_LOGS}
-if [[ -z ${POLICY_LOGS} ]]; then
+if [ -z "${POLICY_LOGS}" ]; then
_LOGS="${POLICY_HOME}"/logs
fi
@@ -263,9 +260,9 @@ status)
echo "$_STATUS"
;;
start)
- if flock ${cfg}; then
+ if flock 200; then
start
- fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
+ fi 200>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
;;
umstart)
um_start
@@ -274,19 +271,19 @@ exec)
exec_start
;;
stop)
- if flock ${cfg}; then
+ if flock 200; then
stop
- fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
+ fi 200>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
;;
umstop)
um_stop
;;
restart)
- if flock ${cfg}; then
- stop
- sleep 2
- start
- fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
+ if flock 200; then
+ stop
+ sleep 2
+ start
+ fi 200>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock
;;
*)
echo "error: invalid option $@"
diff --git a/policy-management/src/main/server-gen/bin/rest-add-controller b/policy-management/src/main/server-gen/bin/rest-add-controller
index 1c7dfbc1..3bd02be8 100644
--- a/policy-management/src/main/server-gen/bin/rest-add-controller
+++ b/policy-management/src/main/server-gen/bin/rest-add-controller
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -8,7 +8,7 @@
# 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
@@ -22,14 +22,14 @@ source $POLICY_HOME/etc/profile.d/env.sh
json=$1-controller.rest.json
-if [ -f ${json} ]; then
- if [[ -n ${TELEMETRY_PASSWORD} ]]; then
- curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X POST --data @${json} --header "Content-Type: application/json" \
- https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers
- else
- curl -k --silent -X POST --data @${json} --header "Content-Type: application/json" \
- https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers
- fi
+if [ -f "${json}" ]; then
+ if [ -n "${TELEMETRY_PASSWORD}" ]; then
+ curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X POST --data @${json} --header "Content-Type: application/json" \
+ https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers
+ else
+ curl -k --silent -X POST --data @${json} --header "Content-Type: application/json" \
+ https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers
+ fi
else
- echo "Usage: rest-add-controller.sh closed-loop-sample|reporter|sepc|vsegw|.. (or any other config file ending with *-controller.rest.json)"
+ echo "Usage: rest-add-controller.sh closed-loop-sample|reporter|sepc|vsegw|.. (or any other config file ending with *-controller.rest.json)"
fi
diff --git a/policy-management/src/main/server-gen/bin/rest-delete-controller b/policy-management/src/main/server-gen/bin/rest-delete-controller
index c2741191..8a8b9f65 100644
--- a/policy-management/src/main/server-gen/bin/rest-delete-controller
+++ b/policy-management/src/main/server-gen/bin/rest-delete-controller
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -20,8 +20,8 @@
source $POLICY_HOME/etc/profile.d/env.sh
-if [[ -n $1 ]]; then
- if [[ -n ${TELEMETRY_PASSWORD} ]]; then
+if [ -n "$1" ]; then
+ if [ -n "${TELEMETRY_PASSWORD}" ]; then
curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X DELETE --header "Content-Type: application/json" \
https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers/${1}
else
diff --git a/policy-management/src/main/server-gen/bin/telemetry b/policy-management/src/main/server-gen/bin/telemetry
index 9d4b857a..cead3d3a 100644
--- a/policy-management/src/main/server-gen/bin/telemetry
+++ b/policy-management/src/main/server-gen/bin/telemetry
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/usr/bin/env ash
# ============LICENSE_START=======================================================
# ONAP
@@ -33,7 +33,7 @@ if ! "${POLICY_HOME}"/bin/policy-management-controller status >/dev/null 2>&1; t
exit 2
fi
-if [[ ! -r ${TELEMETRY_SPEC} ]]; then
+if [ ! -r "${TELEMETRY_SPEC}" ]; then
echo "generating new spec .."
if ! http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" https://localhost:9696/swagger.json >${TELEMETRY_SPEC} 2>/dev/null; then
echo "error: cannot generate telemetry spec"