Java Code Examples for org.apache.commons.configuration2.HierarchicalConfiguration#isEmpty()

The following examples show how to use org.apache.commons.configuration2.HierarchicalConfiguration#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuditServiceInternalImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuditLog createAuditLogEntry() {
    AuditLog auditLog = new AuditLog();
    String clusterNodeId = StringUtils.EMPTY;
    HierarchicalConfiguration<ImmutableNode> clusterNodeData =
            studioConfiguration.getSubConfig(CLUSTERING_NODE_REGISTRATION);
    if (clusterNodeData != null && !clusterNodeData.isEmpty()) {
        clusterNodeId = clusterNodeData.getString(CLUSTER_MEMBER_LOCAL_ADDRESS);
    }
    auditLog.setOrganizationId(1);
    auditLog.setOrigin(ORIGIN_API);
    auditLog.setClusterNodeId(clusterNodeId);
    return auditLog;
}
 
Example 2
Source File: StudioNodeHeartbeatJob.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
private void updateHeartbeat() {
    HierarchicalConfiguration<ImmutableNode> registrationData = getConfiguration();
    if (registrationData != null && !registrationData.isEmpty()) {
        String localAddress = registrationData.getString(CLUSTER_MEMBER_LOCAL_ADDRESS);
        Map<String, String> params = new HashMap<String, String>();
        params.put(CLUSTER_LOCAL_ADDRESS, localAddress);
        params.put(CLUSTER_STATE, ClusterMember.State.ACTIVE.toString());
        logger.debug("Update heartbeat for cluster member with local address: " + localAddress);
        clusterDAO.updateHeartbeat(params);
    }
}
 
Example 3
Source File: StudioClusterSyncJobImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    if (singleWorkerLock.tryLock()) {
        try {
            logger.debug("Starting Cluster Sync worker");
            HierarchicalConfiguration<ImmutableNode> registrationData = getConfiguration();
            if (registrationData != null && !registrationData.isEmpty()) {
                String localAddress = registrationData.getString(CLUSTER_MEMBER_LOCAL_ADDRESS);
                logger.debug("Cluster is configured.");
                List<ClusterMember> cm = clusterDAO.getAllMembers();
                boolean memberRemoved =
                        !cm.stream().anyMatch(clusterMember -> {
                            return clusterMember.getLocalAddress().equals(localAddress);
                        });
                if (memberRemoved) {
                    logger.info("Cluster member " + localAddress + " is removed from cluster. Not syncing with other " +
                            "members");
                    DeployContentToEnvironmentStore.signalToStop(true);
                } else {
                    logger.debug("Cluster members count " + cm.size());
                    try {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put(CLUSTER_LOCAL_ADDRESS, localAddress);
                        params.put(CLUSTER_STATE, ClusterMember.State.ACTIVE.toString());
                        List<ClusterMember> clusterMembers = clusterDAO.getOtherMembers(params);

                        if (repositoryType.equals(GitRepositories.GLOBAL)) {
                            StudioNodeSyncGlobalRepoTask nodeGlobalRepoSyncTask =
                                    new StudioNodeSyncGlobalRepoTask();
                            nodeGlobalRepoSyncTask.setClusterNodes(clusterMembers);
                            nodeGlobalRepoSyncTask.setContentRepository(contentRepository);
                            nodeGlobalRepoSyncTask.setStudioConfiguration(studioConfiguration);
                            taskExecutor.execute(nodeGlobalRepoSyncTask);
                        } else {
                            cleanupDeletedSites();

                            Set<String> siteNames = siteService.getAllAvailableSites();


                            if (logger.getLevel().equals(Logger.LEVEL_DEBUG)) {
                                int numActiveMembers = clusterDAO.countActiveMembers(params);
                                logger.debug("Number of active cluster members: " + numActiveMembers);
                            }
                            if ((clusterMembers != null && clusterMembers.size() > 0) && (siteNames != null && siteNames.size() > 0)) {
                                for (String site : siteNames) {
                                    SiteFeed siteFeed = siteService.getSite(site);
                                    logger.debug("Creating task thread to sync cluster node for site " + site);
                                    switch (repositoryType) {
                                        case SANDBOX:
                                            StudioNodeSyncSandboxTask nodeSandobxSyncTask = new StudioNodeSyncSandboxTask();
                                            nodeSandobxSyncTask.setSiteId(site);
                                            nodeSandobxSyncTask.setSiteUuid(siteFeed.getSiteUuid());
                                            nodeSandobxSyncTask.setSearchEngine(siteFeed.getSearchEngine());
                                            nodeSandobxSyncTask.setDeployer(deployer);
                                            nodeSandobxSyncTask.setStudioConfiguration(studioConfiguration);
                                            nodeSandobxSyncTask.setContentRepository(contentRepository);
                                            nodeSandobxSyncTask.setSiteService(siteService);
                                            nodeSandobxSyncTask.setServicesConfig(servicesConfig);
                                            nodeSandobxSyncTask.setClusterNodes(clusterMembers);
                                            nodeSandobxSyncTask.setDeploymentService(deploymentService);
                                            taskExecutor.execute(nodeSandobxSyncTask);
                                            break;
                                        case PUBLISHED:
                                            StudioNodeSyncPublishedTask nodePublishedSyncTask = new StudioNodeSyncPublishedTask();
                                            nodePublishedSyncTask.setSiteId(site);
                                            nodePublishedSyncTask.setSiteUuid(siteFeed.getSiteUuid());
                                            nodePublishedSyncTask.setSearchEngine(siteFeed.getSearchEngine());
                                            nodePublishedSyncTask.setDeployer(deployer);
                                            nodePublishedSyncTask.setStudioConfiguration(studioConfiguration);
                                            nodePublishedSyncTask.setContentRepository(contentRepository);
                                            nodePublishedSyncTask.setSiteService(siteService);
                                            nodePublishedSyncTask.setServicesConfig(servicesConfig);
                                            nodePublishedSyncTask.setClusterNodes(clusterMembers);
                                            nodePublishedSyncTask.setDeploymentService(deploymentService);
                                            taskExecutor.execute(nodePublishedSyncTask);
                                            break;
                                    }
                                }
                            }
                        }
                    } catch (Exception err) {
                        logger.error("Error while executing cluster sync job", err);
                    }
                }
            }
        } finally {
            singleWorkerLock.unlock();
        }
        logger.debug("Cluster Sync worker finished");
    }
}
 
Example 4
Source File: ClusterNodeRegistrationImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
public void init() {
    logger.debug("Autoregister cluster if cluster node is configured");
    HierarchicalConfiguration<ImmutableNode> registrationData = getConfiguration();
    ClusterMember clusterMember = new ClusterMember();
    if (registrationData != null && !registrationData.isEmpty()) {
        try {
            logger.debug("Collect and populate data for cluster node registration");
            clusterMember.setLocalAddress(registrationData.getString(CLUSTER_MEMBER_LOCAL_ADDRESS));
            if (!isRegistered(clusterMember.getLocalAddress())) {
                Path path = Paths.get(studioConfiguration.getProperty(REPO_BASE_PATH),
                                      studioConfiguration.getProperty(SITES_REPOS_PATH));
                String authenticationType = registrationData.getString(CLUSTER_MEMBER_AUTHENTICATION_TYPE);
                String username = registrationData.getString(CLUSTER_MEMBER_USERNAME);
                String password = registrationData.getString(CLUSTER_MEMBER_PASSWORD);
                String token = registrationData.getString(CLUSTER_MEMBER_TOKEN);
                String privateKey = registrationData.getString(CLUSTER_MEMBER_PRIVATE_KEY);
                String gitUrl = studioConfiguration.getProperty(CLUSTERING_SYNC_URL_FORMAT);
                if (StringUtils.isEmpty(username)) {
                    gitUrl = gitUrl.replace("{username}@", "");
                } else {
                    gitUrl = gitUrl.replace("{username}", username);
                }
                gitUrl = gitUrl.replace("{localAddress}", clusterMember.getLocalAddress())
                               .replace("{absolutePath}", path.toAbsolutePath().normalize().toString())
                         + "/{siteId}";
                clusterMember.setGitUrl(gitUrl);
                clusterMember.setState(ClusterMember.State.ACTIVE);
                clusterMember.setGitRemoteName(getGitRemoteName(clusterMember));
                clusterMember.setGitAuthType(authenticationType.toLowerCase());
                clusterMember.setGitUsername(username);
                TextEncryptor encryptor = null;
                encryptor = new PbkAesTextEncryptor(studioConfiguration.getProperty(SECURITY_CIPHER_KEY),
                                                    studioConfiguration.getProperty(SECURITY_CIPHER_SALT));
                if (StringUtils.isEmpty(password)) {
                    clusterMember.setGitPassword(password);
                } else {
                    String hashedPassword = encryptor.encrypt(password);
                    clusterMember.setGitPassword(hashedPassword);
                }

                if (StringUtils.isEmpty(token)) {
                    clusterMember.setGitToken(token);
                } else {
                    String hashedToken = encryptor.encrypt(token);
                    clusterMember.setGitToken(hashedToken);
                }

                if (StringUtils.isEmpty(privateKey)) {
                    clusterMember.setGitPrivateKey(privateKey);
                } else {
                    String hashedPrivateKey = encryptor.encrypt(privateKey);
                    clusterMember.setGitPrivateKey(hashedPrivateKey);
                }

                logger.debug("Register cluster member");
                registerClusterNode(clusterMember);
            }
        } catch (CryptoException e) {
            logger.error("Failed to register cluster member");
        }
    }
}
 
Example 5
Source File: ClusterNodeRegistrationImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
public void destroy() {
    HierarchicalConfiguration<ImmutableNode> registrationData = getConfiguration();
    if (registrationData != null && !registrationData.isEmpty()) {
        removeClusterNode(registrationData.getString(CLUSTER_MEMBER_LOCAL_ADDRESS));
    }
}