Package com.netflix.paas.cassandra.entity

Examples of com.netflix.paas.cassandra.entity.CassandraClusterEntity


    @Override
    public void execte(TaskContext context) throws Exception{
        // Get parameters from the context
        String clusterName = context.getStringParameter("cluster");
        Boolean ignoreSystem = context.getBooleanParameter("ignoreSystem", true);
        CassandraClusterEntity entity = (CassandraClusterEntity)context.getParamater("entity");
       
        LOG.info("Refreshing cluster " + clusterName);
       
        // Read the current state from the DAO
//        CassandraClusterEntity entity = clusterDao.read(clusterName);
       
        Map<String, String> existingKeyspaces = entity.getKeyspaces();
        if (existingKeyspaces == null) {
            existingKeyspaces = Maps.newHashMap();
            entity.setKeyspaces(existingKeyspaces);
        }
       
        Map<String, String> existingColumnFamilies = entity.getColumnFamilies();
        if (existingColumnFamilies == null) {
            existingColumnFamilies = Maps.newHashMap();
            entity.setColumnFamilies(existingColumnFamilies);
        }
       
        Set<String> foundKeyspaces      = Sets.newHashSet();
        Set<String> foundColumnFamilies = Sets.newHashSet();
       
        Cluster cluster = provider.acquireCluster(new ClusterKey(entity.getClusterName(), entity.getDiscoveryType()));
       
        boolean changed = false;
       
//        // Iterate found keyspaces
        try {
            for (KeyspaceDefinition keyspace : cluster.describeKeyspaces()) {
                // Extract data from the KeyspaceDefinition
                String ksName = keyspace.getName();
                MapStringToObject keyspaceOptions = getKeyspaceOptions(keyspace);
               
                if (existingKeyspaces.containsKey(ksName)) {
                    MapStringToObject previousOptions = JsonSerializer.fromString(existingKeyspaces.get(ksName), MapStringToObject.class);
                    MapDifference keyspaceDiff = Maps.difference(keyspaceOptions, previousOptions);
                    if (keyspaceDiff.areEqual()) {
                        LOG.info("Keyspace '{}' didn't change", new Object[]{ksName});
                    }
                    else {
                        changed = true;
                        LOG.info("CF Changed: " + keyspaceDiff.entriesDiffering());
                    }
                }
                else {
                    changed = true;
                }
                String strKeyspaceOptions = JsonSerializer.toString(keyspaceOptions);
               
//                // Keep track of keyspace
                foundKeyspaces.add(keyspace.getName());
                existingKeyspaces.put(ksName, strKeyspaceOptions);
               
                LOG.info("Found keyspace '{}|{}' : {}", new Object[]{entity.getClusterName(), ksName, keyspaceOptions});
               
//                // Iterate found column families
                for (ColumnFamilyDefinition cf : keyspace.getColumnFamilyList()) {
                    // Extract data from the ColumnFamilyDefinition
                    String cfName = String.format("%s|%s", keyspace.getName(), cf.getName());
                    MapStringToObject cfOptions = getColumnFamilyOptions(cf);
                    String strCfOptions = JsonSerializer.toString(cfOptions);
//                   
//                    // Check for changes
                    if (existingColumnFamilies.containsKey(cfName)) {
                        MapStringToObject previousOptions = JsonSerializer.fromString(existingColumnFamilies.get(cfName), MapStringToObject.class);
                       
                        LOG.info("Old options: " + previousOptions);
                       
                        MapDifference cfDiff = Maps.difference(cfOptions, previousOptions);
                        if (cfDiff.areEqual()) {
                            LOG.info("CF '{}' didn't change", new Object[]{cfName});
                        }
                        else {
                            changed = true;
                            LOG.info("CF Changed: " + cfDiff.entriesDiffering());
                        }

                    }
                    else {
                        changed = true;
                    }
//                   
//                    // Keep track of the cf
                    foundColumnFamilies.add(cfName);
                    existingColumnFamilies.put(cfName,  strCfOptions);
                   
                    LOG.info("Found column family '{}|{}|{}' : {}", new Object[]{entity.getClusterName(), keyspace.getName(), cf.getName(), strCfOptions});
                }
            }
        }
        catch (Exception e) {
            LOG.info("Error refreshing cluster: " + entity.getClusterName(), e);
            entity.setEnabled(false);
        }
       
        SetView<String> ksRemoved = Sets.difference(existingKeyspaces.keySet(),      foundKeyspaces);
        LOG.info("Keyspaces removed: " + ksRemoved);
       
View Full Code Here


                }
            });

        // Iterate through new list of clusters and look for changes
        for (String clusterName : clusters) {
            CassandraClusterEntity entity = existingClusters.get(clusterName);
           
            // This is a new cluster
            if (entity == null) {
                LOG.info("Found new cluster : " + clusterName);
               
                entity = CassandraClusterEntity.builder()
                        .withName(clusterName)
                        .withIsEnabled(true)
                        .withDiscoveryType(discoveryService.getName())
                        .build();
               
                try {
                    clusterDao.write(entity);
                }
                catch (Exception e) {
                    LOG.warn("Failed to persist cluster info for '{}'", new Object[]{clusterName, e});
                }
               
                updateCluster(entity);
            }
           
            // We knew about it before and it is disabled
            else if (!entity.isEnabled()) {
                LOG.info("Cluster '{}' is disabled and will not be refreshed", new Object[]{clusterName});
            }
           
            // Refresh the info for an existing cluster
            else {
                LOG.info("Cluster '{}' is being refreshed", new Object[]{clusterName});
                if (entity.getDiscoveryType() == null) {
                    entity.setDiscoveryType(discoveryService.getName());
                    try {
                        clusterDao.write(entity);
                    }
                    catch (Exception e) {
                        LOG.warn("Failed to persist cluster info for '{}'", new Object[]{clusterName, e});
View Full Code Here

TOP

Related Classes of com.netflix.paas.cassandra.entity.CassandraClusterEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.