- 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 String DEFAULT_VERSION = "1.1.0-SNAPSHOT";
- private static final String DEPENDENCY_FILE = "dependency.json";
-
- private static Map<String, String> modifiedGroups = new HashMap<>();
- private static IntegrityMonitor im;
- private static BackUpMonitor bm;
- private static String resourceName = null;
- private String defaultName = null;
- private String repID = null;
- private String repName = null;
- private ArrayList<String> repURLs= null;
- private String repUserName = null;
- private String repPassword = null;
- private String policyKeyID = null;
- private boolean createFlag = false;
- private String uebList = null;
- private List<String> dmaapList = null;
- private String pubTopic = null;
- private PublisherBuilder pubBuilder = null;
- protected BusPublisher publisher = null;
- private Long uebDelay = Long.parseLong("20");
- private Long dmaapDelay = Long.parseLong("5000");
- private String notificationType = null;
- private ArrayList<ControllerPOJO> controllers;
- private HashMap<String, ArrayList<Object>> groupMap = new HashMap<>();
- private Map<String, String> policyMap = new HashMap<>();
- private String brmsdependencyversion;
- private EntityManager em;
- private boolean syncFlag = false;
-
- public BRMSPush(String propertiesFile, BackUpHandler handler) throws PolicyException{
- Properties config = new Properties();
- Path file = Paths.get(propertiesFile);
- if(Files.notExists(file)){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Config File doesn't Exist in the specified Path " + file.toString());
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE+"Config File doesn't Exist in the specified Path " + file.toString());
- }else{
- if(file.toString().endsWith(".properties")){
- // Grab the Properties.
- setProperty(file, config, handler);
- }
- }
- }
-
- private void setProperty(Path file, Properties config, BackUpHandler handler) throws PolicyException{
- InputStream in;
- try {
- in = new FileInputStream(file.toFile());
- config.load(in);
- } catch (IOException e) {
- LOGGER.error(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.");
- }
- LOGGER.info("Trying to set up IntegrityMonitor");
- try {
- LOGGER.info("Trying to set up IntegrityMonitor");
- resourceName = config.getProperty("RESOURCE_NAME");
- if(resourceName==null){
- LOGGER.warn("RESOURCE_NAME is missing setting default value. ");
- resourceName = "brmsgw_pdp01";
- }
- resourceName = resourceName.trim();
- im = IntegrityMonitor.getInstance(resourceName, config);
- } catch (Exception e) {
- LOGGER.error("Error starting Integerity Monitor: " + e);
- }
- LOGGER.info("Trying to set up BackUpMonitor");
- try {
- bm = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), resourceName, config, handler);
- } catch (Exception e) {
- LOGGER.error("Error starting BackUpMonitor: " + e);
- }
- config.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistenceBRMS.xml");
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("BRMSGW", config);
- em = emf.createEntityManager();
- defaultName = config.getProperty("defaultName");
- if(defaultName==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "defaultName property is missing from the property file ");
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "defaultName property is missing from the property file");
- }
- defaultName = defaultName.trim();
- repID = config.getProperty("repositoryID");
- if(repID==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryID property is missing from the property file ");
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryID property is missing from the property file ");
- }
- repID = repID.trim();
- repName = config.getProperty("repositoryName");
- if(repName==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryName property is missing from the property file ");
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryName property is missing from the property file ");
- }
- repName = repName.trim();
- String repURL = config.getProperty("repositoryURL");
- if(repURL==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryURL property is missing from the property file ");
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryURL property is missing from the property file ");
- }
- if(repURL.contains(",")){
- repURLs = new ArrayList<>(Arrays.asList(repURL.trim().split(",")));
- }else{
- repURLs = new ArrayList<>();
- repURLs.add(repURL);
- }
- repUserName = config.getProperty("repositoryUsername");
- repPassword = config.getProperty("repositoryPassword");
- if(repUserName==null || repPassword==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repostoryUserName and respositoryPassword properties are required.");
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "repostoryUserName and respositoryPassword properties are required.");
- }
- repUserName = repUserName.trim();
- repPassword = repPassword.trim();
- policyKeyID = config.getProperty("policyKeyID");
- if(policyKeyID==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "policyKeyID property is missing from the property file ");
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "policyKeyID property is missing from the property file ");
- }
- policyKeyID = policyKeyID.trim();
- String syncF = config.getProperty("sync", "false").trim();
- syncFlag = Boolean.parseBoolean(syncF);
- if(syncFlag){
- PolicyLogger.info("SYNC Flag is turned ON. DB will be given Priority.");
- }
- brmsdependencyversion = config.getProperty("brms.dependency.version");
- if(brmsdependencyversion==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "brmsdependencyversion property is missing from the property file, Using default Version.");
- brmsdependencyversion = DEFAULT_VERSION;
- }
- brmsdependencyversion = brmsdependencyversion.trim();
- readGroups(config);
-
- // Setup Publisher
- notificationType = config.getProperty("NOTIFICATION_TYPE");
- if("dmaap".equalsIgnoreCase(notificationType)){
-
- LOGGER.info("Notification Type being used is DMaaP... creating instance of BusPublisher.");
- // Setting up the Publisher for DMaaP MR
- String dmaapServers = config.getProperty("NOTIFICATION_SERVERS");
- pubTopic = config.getProperty("NOTIFICATION_TOPIC");
- String aafLogin = config.getProperty("CLIENT_ID").trim();
- String aafPassword = config.getProperty("CLIENT_KEY").trim();
-
- if(dmaapServers==null || pubTopic==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "DMaaP properties are missing from the property file ");
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "DMaaP properties are missing from the property file ");
- }
-
- dmaapServers = dmaapServers.trim();
- pubTopic = pubTopic.trim();
-
- if(dmaapServers.contains(",")) {
- dmaapList = new ArrayList<>(Arrays.asList(dmaapServers.split("\\s*,\\s*")));
- } else {
- dmaapList = new ArrayList<>();
- dmaapList.add(dmaapServers);
- }
-
- this.publisher =
- new BusPublisher.DmaapPublisherWrapper(this.dmaapList,
- this.pubTopic,
- aafLogin,
- aafPassword);
-
-
- String dDelay = config.getProperty("NOTIFICATION_DELAY");
- if(dDelay!=null && !dDelay.isEmpty()){
- dDelay = dDelay.trim();
- try{
- dmaapDelay = Long.parseLong(dDelay);
- }catch (NumberFormatException e){
- LOGGER.error("DMAAP_DELAY not a long format number" + e);
- }
- }
- LOGGER.info("DMAAP BusPublisher is created.");
-
- } else {
- LOGGER.info("Notification Type being used is UEB... creating instance of PublisherBuilder.");
- // Setting up the Publisher for UEB
- uebList = config.getProperty("NOTIFICATION_SERVERS");
- pubTopic = config.getProperty("NOTIFICATION_TOPIC");
- String apiKey = config.getProperty("UEB_API_KEY");
- String apiSecret = config.getProperty("UEB_API_SECRET");
- if(uebList==null || pubTopic==null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file ");
- throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file ");
- }
- uebList = uebList.trim();
- pubTopic = pubTopic.trim();
- pubBuilder = new CambriaClientBuilders.PublisherBuilder();
- pubBuilder.usingHosts(uebList).onTopic(pubTopic);
- if(apiKey!=null && !apiKey.isEmpty() &&
- apiSecret!=null && !apiSecret.isEmpty()) {
- apiKey= apiKey.trim();
- apiSecret = apiSecret.trim();
- pubBuilder.authenticatedBy(apiKey, apiSecret);
- }
- String uDelay = config.getProperty("NOTIFICATION_DELAY");
- if(uDelay!=null && !uDelay.isEmpty()){
- uDelay = uDelay.trim();
- try{
- uebDelay = Long.parseLong(uDelay);
- }catch (NumberFormatException e){
- LOGGER.error("UEB_DELAY not a long format number" + e);
- }
- }
- LOGGER.info("UEB PublisherBuilder is created.");
-
- }
-
- }
-
- /**
- * Will Initialize the variables required for BRMSPush.
- */
- public void initiate(boolean flag) {
- modifiedGroups = new HashMap<>();
- controllers = new ArrayList<>();
- try {
- bm.updateNotification();
- } catch (Exception e) {
- LOGGER.error("Error while updating Notification: " + e.getMessage());
- }
- if(flag) syncGroupInfo();
- }
-
- /**
- * Will Add rules to projects. Creates necessary folders if required.
- */
- public void addRule(String name, String rule, Map<String, String> responseAttributes) {
- // 1 check the response Attributes and determine if this belongs to any projects.
- // 2 if not create folder
- // 3 create pom.
- // 4 copy the rule.
- // 5 store the groups that have been updated.
- String kSessionName=null;
- String selectedName = null;
- if(!responseAttributes.isEmpty()){
- // Pick selected Value
- String userControllerName = null;
- ArrayList<PEDependency> userDependencies = new ArrayList<>();
- for(String key: responseAttributes.keySet()){
- if(key.equals(policyKeyID)){
- selectedName = responseAttributes.get(key);
- }
- //kmodule configurations
- else if (key.equals("kSessionName")){
- kSessionName=responseAttributes.get(key);
- }
- // Check User Specific values.
+ 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 String DEFAULT_VERSION = "1.1.0-SNAPSHOT";
+ private static final String DEPENDENCY_FILE = "dependency.json";
+
+ private static Map<String, String> modifiedGroups = new HashMap<>();
+ private static IntegrityMonitor im;
+ private static BackUpMonitor bm;
+ private String defaultName = null;
+ private String repID = null;
+ private String repName = null;
+ private ArrayList<String> repURLs = null;
+ private String repUserName = null;
+ private String repPassword = null;
+ private String policyKeyID = null;
+ private boolean createFlag = false;
+ private String uebList = null;
+ private List<String> dmaapList = null;
+ private String pubTopic = null;
+ private PublisherBuilder pubBuilder = null;
+ protected BusPublisher publisher = null;
+ private Long uebDelay = Long.parseLong("20");
+ private Long dmaapDelay = Long.parseLong("5000");
+ private String notificationType = null;
+ private ArrayList<ControllerPOJO> controllers;
+ private HashMap<String, ArrayList<Object>> groupMap = new HashMap<>();
+ private Map<String, String> policyMap = new HashMap<>();
+ private String brmsdependencyversion;
+ private EntityManager em;
+ private boolean syncFlag = false;
+
+ public BRMSPush(String propertiesFile, BackUpHandler handler) throws PolicyException {
+ Properties config = new Properties();
+ Path file = Paths.get(propertiesFile);
+ if (Files.notExists(file)) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Config File doesn't Exist in the specified Path "
+ + file.toString());
+ throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "Config File doesn't Exist in the specified Path " + file.toString());
+ } else {
+ if (file.toString().endsWith(".properties")) {
+ // Grab the Properties.
+ setProperty(file, config, handler);
+ }
+ }
+ }
+
+ private void setProperty(Path file, Properties config, BackUpHandler handler) throws PolicyException {
+ InputStream in;
+ try {
+ in = new FileInputStream(file.toFile());
+ config.load(in);
+ } catch (IOException e) {
+ LOGGER.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Data/File Read Error while reading from the property file.",
+ e);
+ throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "Data/File Read Error while reading from the property file.");
+ }
+ LOGGER.info("Trying to set up IntegrityMonitor");
+ String resourceName = null;
+ try {
+ LOGGER.info("Trying to set up IntegrityMonitor");
+ resourceName = config.getProperty("RESOURCE_NAME");
+ if (resourceName == null) {
+ LOGGER.warn("RESOURCE_NAME is missing setting default value. ");
+ resourceName = "brmsgw_pdp01";
+ }
+ resourceName = resourceName.trim();
+ setIntegrityMonitor(IntegrityMonitor.getInstance(resourceName, config));
+ } catch (Exception e) {
+ LOGGER.error("Error starting Integerity Monitor: " + e);
+ }
+ LOGGER.info("Trying to set up BackUpMonitor");
+ try {
+ setBackupMonitor(BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), resourceName, config,
+ handler));
+ } catch (Exception e) {
+ LOGGER.error("Error starting BackUpMonitor: " + e);
+ }
+ config.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistenceBRMS.xml");
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("BRMSGW", config);
+ em = emf.createEntityManager();
+ defaultName = config.getProperty("defaultName");
+ if (defaultName == null) {
+ LOGGER.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "defaultName property is missing from the property file ");
+ throw new PolicyException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "defaultName property is missing from the property file");
+ }
+ defaultName = defaultName.trim();
+ repID = config.getProperty("repositoryID");
+ if (repID == null) {
+ LOGGER.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryID property is missing from the property file ");
+ throw new PolicyException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryID property is missing from the property file ");
+ }
+ repID = repID.trim();
+ repName = config.getProperty("repositoryName");
+ if (repName == null) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "repositoryName property is missing from the property file ");
+ throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "repositoryName property is missing from the property file ");
+ }
+ repName = repName.trim();
+ String repURL = config.getProperty("repositoryURL");
+ if (repURL == null) {
+ LOGGER.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryURL property is missing from the property file ");
+ throw new PolicyException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryURL property is missing from the property file ");
+ }
+ if (repURL.contains(",")) {
+ repURLs = new ArrayList<>(Arrays.asList(repURL.trim().split(",")));
+ } else {
+ repURLs = new ArrayList<>();
+ repURLs.add(repURL);
+ }
+ repUserName = config.getProperty("repositoryUsername");
+ repPassword = config.getProperty("repositoryPassword");
+ if (repUserName == null || repPassword == null) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "repostoryUserName and respositoryPassword properties are required.");
+ throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "repostoryUserName and respositoryPassword properties are required.");
+ }
+ repUserName = repUserName.trim();
+ repPassword = repPassword.trim();
+ policyKeyID = config.getProperty("policyKeyID");
+ if (policyKeyID == null) {
+ LOGGER.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "policyKeyID property is missing from the property file ");
+ throw new PolicyException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "policyKeyID property is missing from the property file ");
+ }
+ policyKeyID = policyKeyID.trim();
+ String syncF = config.getProperty("sync", "false").trim();
+ syncFlag = Boolean.parseBoolean(syncF);
+ if (syncFlag) {
+ PolicyLogger.info("SYNC Flag is turned ON. DB will be given Priority.");
+ }
+ brmsdependencyversion = config.getProperty("brms.dependency.version");
+ if (brmsdependencyversion == null) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "brmsdependencyversion property is missing from the property file, Using default Version.");
+ brmsdependencyversion = DEFAULT_VERSION;
+ }
+ brmsdependencyversion = brmsdependencyversion.trim();
+ readGroups(config);
+
+ // Setup Publisher
+ notificationType = config.getProperty("NOTIFICATION_TYPE");
+ if ("dmaap".equalsIgnoreCase(notificationType)) {
+
+ LOGGER.info("Notification Type being used is DMaaP... creating instance of BusPublisher.");
+ // Setting up the Publisher for DMaaP MR
+ String dmaapServers = config.getProperty("NOTIFICATION_SERVERS");
+ pubTopic = config.getProperty("NOTIFICATION_TOPIC");
+ String aafLogin = config.getProperty("CLIENT_ID").trim();
+ String aafPassword = config.getProperty("CLIENT_KEY").trim();
+
+ if (dmaapServers == null || pubTopic == null) {
+ LOGGER.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "DMaaP properties are missing from the property file ");
+ throw new PolicyException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "DMaaP properties are missing from the property file ");
+ }
+
+ dmaapServers = dmaapServers.trim();
+ pubTopic = pubTopic.trim();
+
+ if (dmaapServers.contains(",")) {
+ dmaapList = new ArrayList<>(Arrays.asList(dmaapServers.split("\\s*,\\s*")));
+ } else {
+ dmaapList = new ArrayList<>();
+ dmaapList.add(dmaapServers);
+ }
+
+ this.publisher = new BusPublisher.DmaapPublisherWrapper(this.dmaapList, this.pubTopic, aafLogin,
+ aafPassword);
+
+ String dDelay = config.getProperty("NOTIFICATION_DELAY");
+ if (dDelay != null && !dDelay.isEmpty()) {
+ dDelay = dDelay.trim();
+ try {
+ dmaapDelay = Long.parseLong(dDelay);
+ } catch (NumberFormatException e) {
+ LOGGER.error("DMAAP_DELAY not a long format number" + e);
+ }
+ }
+ LOGGER.info("DMAAP BusPublisher is created.");
+
+ } else {
+ LOGGER.info("Notification Type being used is UEB... creating instance of PublisherBuilder.");
+ // Setting up the Publisher for UEB
+ uebList = config.getProperty("NOTIFICATION_SERVERS");
+ pubTopic = config.getProperty("NOTIFICATION_TOPIC");
+ String apiKey = config.getProperty("UEB_API_KEY");
+ String apiSecret = config.getProperty("UEB_API_SECRET");
+ if (uebList == null || pubTopic == null) {
+ LOGGER.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file ");
+ throw new PolicyException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file ");
+ }
+ uebList = uebList.trim();
+ pubTopic = pubTopic.trim();
+ pubBuilder = new CambriaClientBuilders.PublisherBuilder();
+ pubBuilder.usingHosts(uebList).onTopic(pubTopic);
+ if (apiKey != null && !apiKey.isEmpty() && apiSecret != null && !apiSecret.isEmpty()) {
+ apiKey = apiKey.trim();
+ apiSecret = apiSecret.trim();
+ pubBuilder.authenticatedBy(apiKey, apiSecret);
+ }
+ String uDelay = config.getProperty("NOTIFICATION_DELAY");
+ if (uDelay != null && !uDelay.isEmpty()) {
+ uDelay = uDelay.trim();
+ try {
+ uebDelay = Long.parseLong(uDelay);
+ } catch (NumberFormatException e) {
+ LOGGER.error("UEB_DELAY not a long format number" + e);
+ }
+ }
+ LOGGER.info("UEB PublisherBuilder is created.");
+
+ }
+
+ }
+
+ private static void setBackupMonitor(BackUpMonitor instance) {
+ bm = instance;
+ }
+
+ private static void setIntegrityMonitor(IntegrityMonitor instance) {
+ im = instance;
+ }
+
+ /**
+ * Will Initialize the variables required for BRMSPush.
+ */
+ public void initiate(boolean flag) {
+ resetModifiedGroups();
+ controllers = new ArrayList<>();
+ try {
+ bm.updateNotification();
+ } catch (Exception e) {
+ LOGGER.error("Error while updating Notification: " + e.getMessage(), e);
+ }
+ if (flag)
+ syncGroupInfo();
+ }
+
+ private static void resetModifiedGroups() {
+ modifiedGroups = new HashMap<>();
+ }
+
+ /**
+ * Will Add rules to projects. Creates necessary folders if required.
+ */
+ public void addRule(String name, String rule, Map<String, String> responseAttributes) {
+ // 1 check the response Attributes and determine if this belongs to any projects.
+ // 2 if not create folder
+ // 3 create pom.
+ // 4 copy the rule.
+ // 5 store the groups that have been updated.
+ String kSessionName = null;
+ String selectedName = null;
+ if (!responseAttributes.isEmpty()) {
+ // Pick selected Value
+ String userControllerName = null;
+ ArrayList<PEDependency> userDependencies = new ArrayList<>();
+ for (String key : responseAttributes.keySet()) {
+ if (key.equals(policyKeyID)) {
+ selectedName = responseAttributes.get(key);
+ }
+ // kmodule configurations
+ else if (key.equals("kSessionName")) {
+ kSessionName = responseAttributes.get(key);
+ }
+ // Check User Specific values.