* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
* ================================================================================
* 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
* ================================================================================
* 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
* 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.
* 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.
import com.att.nsa.cambria.client.CambriaClientBuilders;
import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.att.nsa.cambria.client.CambriaClientBuilders;
import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import javax.ws.rs.ProcessingException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import javax.ws.rs.ProcessingException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.maven.model.Dependency;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker;
import org.codehaus.plexus.util.IOUtil;
import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.WriterFactory;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.onap.policy.api.PEDependency;
import org.codehaus.plexus.util.WriterFactory;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.onap.policy.api.PEDependency;
import org.onap.policy.utils.BackUpHandler;
import org.onap.policy.utils.BackUpMonitor;
import org.onap.policy.utils.BusPublisher;
import org.onap.policy.utils.BackUpHandler;
import org.onap.policy.utils.BackUpMonitor;
import org.onap.policy.utils.BusPublisher;
import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
/**
* BRMSPush: Application responsible to push policies to the BRMS PDP Policy Repository (PR).
* Mavenize and push policy to PR
import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
/**
* BRMSPush: Application responsible to push policies to the BRMS PDP Policy Repository (PR).
* Mavenize and push policy to PR
private static final String DROOLS_APPS_TEMPLATE_GROUP =
"org.onap.policy.drools-applications.controlloop.templates";
private static final String DROOLS_APPS_MODEL_GROUP =
private static final String DROOLS_APPS_TEMPLATE_GROUP =
"org.onap.policy.drools-applications.controlloop.templates";
private static final String DROOLS_APPS_MODEL_GROUP =
private static final String META_INF = "META-INF";
private static final String KMODULE_XML_FILE = "kmodule.xml";
private static final String POM_XML_FILE = "pom.xml";
private static final String META_INF = "META-INF";
private static final String KMODULE_XML_FILE = "kmodule.xml";
private static final String POM_XML_FILE = "pom.xml";
private static final Logger LOGGER = FlexLogger.getLogger(BrmsPush.class.getName());
private static final String PROJECTSLOCATION = "RuleProjects";
private static final String[] GOALS = {"clean", "deploy"};
private static final Logger LOGGER = FlexLogger.getLogger(BrmsPush.class.getName());
private static final String PROJECTSLOCATION = "RuleProjects";
private static final String[] GOALS = {"clean", "deploy"};
private static Map<String, String> modifiedGroups = new HashMap<>();
private static IntegrityMonitor im;
private static Map<String, String> modifiedGroups = new HashMap<>();
private static IntegrityMonitor im;
* @param propertiesFile the properties file
* @param handler the {@link BackUpHandler}
* @throws PolicyException PolicyException related to the operation
* @param propertiesFile the properties file
* @param handler the {@link BackUpHandler}
* @throws PolicyException PolicyException related to the operation
throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ "Data/File Read Error while reading from the property file.");
}
throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ "Data/File Read Error while reading from the property file.");
}
if (repUserName == null || repPassword == null) {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE
+ "repostoryUserName and respositoryPassword properties are required.");
if (repUserName == null || repPassword == null) {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE
+ "repostoryUserName and respositoryPassword properties are required.");
final ArrayList<PEDependency> userDependencies = new ArrayList<>();
for (final Map.Entry<String, String> entry : responseAttributes.entrySet()) {
final String key = entry.getKey();
final ArrayList<PEDependency> userDependencies = new ArrayList<>();
for (final Map.Entry<String, String> entry : responseAttributes.entrySet()) {
final String key = entry.getKey();
String userControllerName = null;
// Check User Specific values.
try {
final PEDependency dependency = PolicyUtils.jsonStringToObject(value, PEDependency.class);
userControllerName = key.replaceFirst("$controller:", "");
String userControllerName = null;
// Check User Specific values.
try {
final PEDependency dependency = PolicyUtils.jsonStringToObject(value, PEDependency.class);
userControllerName = key.replaceFirst("$controller:", "");
addToGroup(userControllerName, dependency);
} catch (final Exception e) {
LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e);
addToGroup(userControllerName, dependency);
} catch (final Exception e) {
LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e);
- private void updateUserDependencies(ArrayList<PEDependency> userDependencies, String value) {
- //update the user dependencies supplied as parameter to this method
+ private void updateUserDependencies(final ArrayList<PEDependency> userDependencies, String value) {
+ // update the user dependencies supplied as parameter to this method
value = value.substring(1, value.length() - 1).trim();
final List<String> dependencyStrings = Arrays.asList(value.split(Pattern.quote("},{")));
for (final String dependencyString : dependencyStrings) {
try {
userDependencies.add(PolicyUtils.jsonStringToObject(dependencyString, PEDependency.class));
} catch (final Exception e) {
value = value.substring(1, value.length() - 1).trim();
final List<String> dependencyStrings = Arrays.asList(value.split(Pattern.quote("},{")));
for (final String dependencyString : dependencyStrings) {
try {
userDependencies.add(PolicyUtils.jsonStringToObject(dependencyString, PEDependency.class));
} catch (final Exception e) {
LOGGER.info("Updated Local Memory values with values from database.");
} catch (final Exception exception) {
LOGGER.error("Unable to sync group info", exception);
LOGGER.info("Updated Local Memory values with values from database.");
} catch (final Exception exception) {
LOGGER.error("Unable to sync group info", exception);
} catch (final Exception exception) {
LOGGER.error("Unable add policy to database", exception);
et.rollback();
} catch (final Exception exception) {
LOGGER.error("Unable add policy to database", exception);
et.rollback();
- private void parseJarContents(String artifactId, JarFile jar, Enumeration<?> enumEntries) {
+ private void parseJarContents(final String artifactId, final JarFile jar, final Enumeration<?> enumEntries) {
final JarEntry jarEntry = (JarEntry) enumEntries.nextElement();
File file = null;
final String fileName = jarEntry.getName().substring(jarEntry.getName().lastIndexOf("/") + 1);
if (jarEntry.getName().endsWith(".drl")) {
final JarEntry jarEntry = (JarEntry) enumEntries.nextElement();
File file = null;
final String fileName = jarEntry.getName().substring(jarEntry.getName().lastIndexOf("/") + 1);
if (jarEntry.getName().endsWith(".drl")) {
- final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src"
- + File.separator + "main" + File.separator + RESOURCES + File.separator + RULES;
+ final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src" + File.separator
+ + "main" + File.separator + RESOURCES + File.separator + RULES;
new File(path).mkdirs();
if (syncFlag && policyMap.containsKey(fileName.replace(".drl", ""))) {
file = new File(path + File.separator + fileName);
new File(path).mkdirs();
if (syncFlag && policyMap.containsKey(fileName.replace(".drl", ""))) {
file = new File(path + File.separator + fileName);
new File(path).mkdirs();
file = new File(path + File.separator + fileName);
} else if (jarEntry.getName().endsWith(KMODULE_XML_FILE)) {
new File(path).mkdirs();
file = new File(path + File.separator + fileName);
} else if (jarEntry.getName().endsWith(KMODULE_XML_FILE)) {
- final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src"
- + File.separator + "main" + File.separator + RESOURCES + File.separator + META_INF;
+ final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src" + File.separator
+ + "main" + File.separator + RESOURCES + File.separator + META_INF;
* @throws PolicyException PolicyException related to the operation
*/
public void pushRules() throws PolicyException {
* @throws PolicyException PolicyException related to the operation
*/
public void pushRules() throws PolicyException {
} catch (final Exception exception) {
LOGGER.error("Unable add/update policy group to database for controller name: " + name, exception);
et.rollback();
} catch (final Exception exception) {
LOGGER.error("Unable add/update policy group to database for controller name: " + name, exception);
et.rollback();
} catch (final Exception exception) {
LOGGER.error("Unable remove policy from group to database for policy name: " + policyName, exception);
et.rollback();
} catch (final Exception exception) {
LOGGER.error("Unable remove policy from group to database for policy name: " + policyName, exception);
et.rollback();