private void addRemoveSlaves(
      final MasterSlaveEntry entry,
      final ClusterPartition currentPart,
      final ClusterPartition newPart) {
    Set<URI> removedSlaves = new HashSet<URI>(currentPart.getSlaveAddresses());
    removedSlaves.removeAll(newPart.getSlaveAddresses());

    for (URI uri : removedSlaves) {
      currentPart.removeSlaveAddress(uri);

      slaveDown(entry, uri.getHost(), uri.getPort(), FreezeReason.MANAGER);
      log.info("slave {} removed for slot ranges: {}", uri, currentPart.getSlotRanges());
    }

    Set<URI> addedSlaves = new HashSet<URI>(newPart.getSlaveAddresses());
    addedSlaves.removeAll(currentPart.getSlaveAddresses());
    for (final URI uri : addedSlaves) {
      Future<Void> future = entry.addSlave(uri.getHost(), uri.getPort());
      future.addListener(
          new FutureListener<Void>() {
            @Override
            public void operationComplete(Future<Void> future) throws Exception {
              if (!future.isSuccess()) {
                log.error("Can't add slave: " + uri, future.cause());
                return;
              }

              currentPart.addSlaveAddress(uri);
              entry.slaveUp(uri.getHost(), uri.getPort(), FreezeReason.MANAGER);
              log.info("slave {} added for slot ranges: {}", uri, currentPart.getSlotRanges());
            }
          });
    }
  }
Пример #2
0
  private void scan() throws IOException, JAXBException {
    List<String> collectedUris = collectUris();
    log.info(format("Collected URIs: %s (%d elements)", collectedUris, collectedUris.size()));

    DataSource source = loadDataSource(getId());
    if (!getUrl().equals(source.getBaseUrl()) && !baseUrl.equals(source.getBaseUrl()))
      throw new IllegalArgumentException(
          "Data source URL: " + source.getBaseUrl() + " doesn't match URL: " + getUrl());

    Set<String> files = collectURIs(source);

    Set<String> addedUris = new HashSet<>(collectedUris);
    addedUris.removeAll(files);

    Set<String> removedUris = new HashSet<>(files);
    removedUris.removeAll(collectedUris);

    if (hasDataSourcesServer()) {
      if (addedUris.size() > 0) addUrisInChunks(source, addedUris);
      if (removedUris.size() > 0) removeUris(source, removedUris);
    }

    log.info(
        format(
            "Added %d URIs, removed %d URIs out of %d URIs",
            addCount, removeCount, collectedUris.size()));
  }
Пример #3
0
  private void updateSelections() {
    /* Use set intersection/join's to figure out what updates
    have been done */

    /* First, find which temporary bonuses have been removed,
    and which have been added */
    Set<String> newValues = pc.getTempBonusNames();
    Set<String> oldValues = new TreeSet<String>(tempBonusWidgets.keySet());
    oldValues.removeAll(newValues);
    newValues.removeAll(tempBonusWidgets.keySet());

    if (!newValues.isEmpty()) {
      addTempBonus(newValues);
    }
    if (!oldValues.isEmpty()) {
      removeTempBonus(oldValues);
    }

    /* Now, same for equipment sets. */
    newValues.clear();
    oldValues.clear();

    newValues.addAll(equipSet2Set(pc.getEquipSet()));
    oldValues.addAll(eqSetWidgets.keySet());

    oldValues.removeAll(newValues);
    newValues.removeAll(eqSetWidgets.keySet());
    if (!newValues.isEmpty()) {
      addEquipSets(newValues);
    }
    if (!oldValues.isEmpty()) {
      removeEquipSets(oldValues);
    }
  }
Пример #4
0
  public void clear() {
    checkIfLoaded();
    resetSizeEstimator();
    final Collection<Data> lockedKeys =
        lockStore != null ? lockStore.getLockedKeys() : Collections.<Data>emptySet();
    final Map<Data, Record> lockedRecords = new HashMap<Data, Record>(lockedKeys.size());
    // Locked records should not be removed!
    for (Data key : lockedKeys) {
      Record record = records.get(key);
      if (record != null) {
        lockedRecords.put(key, record);
        updateSizeEstimator(calculateRecordSize(record));
      }
    }
    Set<Data> keysToDelete = records.keySet();
    keysToDelete.removeAll(lockedRecords.keySet());

    final MapStoreWrapper store = mapContainer.getStore();
    // Use an ArrayList so that we don't trigger calls to equals or hashCode on the key objects
    Collection<Object> keysObject = new ArrayList<Object>(keysToDelete.size());
    for (Data key : keysToDelete) {
      // todo ea have a clear(Keys) method for optimizations
      removeIndex(key);
      keysObject.add(mapService.toObject(key));
    }

    if (store != null) {
      store.deleteAll(keysObject);
      toBeRemovedKeys.removeAll(keysToDelete);
    }

    clearRecordsMap(lockedRecords);
    cancelAssociatedSchedulers(keysToDelete);
    resetAccessSequenceNumber();
  }
Пример #5
0
  /**
   * Rules of updating AmazonInfo: - instanceId must exist - localIp/privateIp most exist -
   * publicHostname does not necessarily need to exist (e.g. in vpc)
   */
  /* visible for testing */ static boolean shouldUpdate(AmazonInfo newInfo, AmazonInfo oldInfo) {
    if (newInfo.getMetadata().isEmpty()) {
      logger.warn("Newly resolved AmazonInfo is empty, skipping an update cycle");
    } else if (!newInfo.equals(oldInfo)) {
      if (isBlank(newInfo.get(MetaDataKey.instanceId))) {
        logger.warn("instanceId is blank, skipping an update cycle");
        return false;
      } else if (isBlank(newInfo.get(MetaDataKey.localIpv4))) {
        logger.warn("localIpv4 is blank, skipping an update cycle");
        return false;
      } else {
        Set<String> newKeys = new HashSet<>(newInfo.getMetadata().keySet());
        Set<String> oldKeys = new HashSet<>(oldInfo.getMetadata().keySet());

        Set<String> union = new HashSet<>(newKeys);
        union.retainAll(oldKeys);
        newKeys.removeAll(union);
        oldKeys.removeAll(union);

        for (String key : newKeys) {
          logger.info("Adding new metadata {}={}", key, newInfo.getMetadata().get(key));
        }

        for (String key : oldKeys) {
          logger.info("Removing old metadata {}={}", key, oldInfo.getMetadata().get(key));
        }
      }

      return true;
    }
    return false;
  }
  public <T extends TaskRepository> void setRepositories(List<T> repositories) {

    Set<TaskRepository> set = new HashSet<TaskRepository>(myRepositories);
    set.removeAll(repositories);
    myBadRepositories.removeAll(set); // remove all changed reps
    myIssueCache.clear();

    myRepositories.clear();
    myRepositories.addAll(repositories);

    reps:
    for (T repository : repositories) {
      if (repository.isShared() && repository.getUrl() != null) {
        List<TaskProjectConfiguration.SharedServer> servers = getProjectConfiguration().servers;
        TaskRepositoryType type = repository.getRepositoryType();
        for (TaskProjectConfiguration.SharedServer server : servers) {
          if (repository.getUrl().equals(server.url) && type.getName().equals(server.type)) {
            continue reps;
          }
        }
        TaskProjectConfiguration.SharedServer server = new TaskProjectConfiguration.SharedServer();
        server.type = type.getName();
        server.url = repository.getUrl();
        servers.add(server);
      }
    }
  }
 private boolean solveHouse(House house, Set<Integer> combination) {
   Set<Cell> selectedCells = new TreeSet<Cell>();
   for (Cell cell : house.getCells()) {
     if (cell.isSolved()) {
       // This house already contains a cell with
       // one of this quad's numbers.
       if (combination.contains(cell.getDigit())) {
         return false;
       }
       continue;
     }
     Collection<Integer> cellCandidates = cell.getCandidates();
     if (cellCandidates.size() > getSetSize()) {
       // Can't possibly be a subset
       continue;
     }
     Set<Integer> cellCandidatesCopy = new HashSet<Integer>(cellCandidates);
     cellCandidatesCopy.removeAll(combination);
     if (cellCandidatesCopy.size() == 0) {
       selectedCells.add(cell);
     }
   }
   if (selectedCells.size() == getSetSize()) {
     Set<Cell> houseCells = new HashSet<Cell>(house.getCells());
     houseCells.removeAll(selectedCells);
     boolean changed = false;
     for (Cell cell : houseCells) {
       if (cell.removeAll(combination)) {
         changed = true;
       }
     }
     return changed;
   }
   return false;
 }
  private Set<Vertex> computeMinVertexCover(Set<Vertex> side1, Set<Vertex> side2) {
    Set<Vertex> konigSet = new HashSet<Vertex>();
    Set<Vertex> unmatched = new TreeSet<Vertex>(side1);
    unmatched.removeAll(matches);
    // System.out.println("Matches: " + matches);
    // System.out.println("side 1 unmatched set: " + unmatched);

    for (Vertex v : unmatched) {
      konigDFS(konigSet, v, false);
    }

    // System.out.println("Konig set: " + konigSet);

    Set<Vertex> result = new HashSet<Vertex>(side2);
    result.retainAll(konigSet);
    // System.out.println("side 2 intersect konigSet: " + result);

    Set<Vertex> side1notInKonigSet = new HashSet<Vertex>(side1);
    side1notInKonigSet.removeAll(konigSet);
    // System.out.println("side 1 not in Konig set: " + side1notInKonigSet);

    result.addAll(side1notInKonigSet);

    return result;
  }
Пример #9
0
  private List<Node> getClosestNodes(
      Key k, int n, int index, Bucket[] buckets, Collection<Node> exclude) {

    final List<Node> $ = new ArrayList<Node>();
    final Set<Node> t = new HashSet<Node>();
    if (index < 0) index = 0;

    buckets[index].addNodesTo($);

    if ($.size() < n) {
      // look in other buckets
      for (int i = 1; $.size() < n; ++i) {
        if (index + i < buckets.length) {
          buckets[index + i].addNodesTo(t);
          t.removeAll(exclude);
          $.addAll(t);
          t.clear();
        }

        if (0 <= index - i) {
          buckets[index - i].addNodesTo(t);
          t.removeAll(exclude);
          $.addAll(t);
          t.clear();
        }

        if (buckets.length <= index + i && index - i < 0) break;
      }
    }

    return $;
  }
  @Override
  public void apply() throws ConfigurationException {
    List<X509Certificate> existing = myTrustManager.getCertificates();

    Set<X509Certificate> added = new HashSet<X509Certificate>(myCertificates);
    added.removeAll(existing);

    Set<X509Certificate> removed = new HashSet<X509Certificate>(existing);
    removed.removeAll(myCertificates);

    for (X509Certificate certificate : added) {
      if (!myTrustManager.addCertificate(certificate)) {
        throw new ConfigurationException(
            "Cannot add certificate for " + getCommonName(certificate), "Cannot Add Certificate");
      }
    }

    for (X509Certificate certificate : removed) {
      if (!myTrustManager.removeCertificate(certificate)) {
        throw new ConfigurationException(
            "Cannot remove certificate for " + getCommonName(certificate),
            "Cannot Remove Certificate");
      }
    }
    CertificateManager.Config state = CertificateManager.getInstance().getState();

    state.ACCEPT_AUTOMATICALLY = myAcceptAutomatically.isSelected();
    state.CHECK_HOSTNAME = myCheckHostname.isSelected();
    state.CHECK_VALIDITY = myCheckValidityPeriod.isSelected();
  }
  private void checkSlotsMigration(Collection<ClusterPartition> newPartitions) {
    List<ClusterPartition> currentPartitions =
        new ArrayList<ClusterPartition>(lastPartitions.values());
    for (ClusterPartition currentPartition : currentPartitions) {
      for (ClusterPartition newPartition : newPartitions) {
        if (!currentPartition.getNodeId().equals(newPartition.getNodeId())) {
          continue;
        }

        Set<ClusterSlotRange> addedSlots =
            new HashSet<ClusterSlotRange>(newPartition.getSlotRanges());
        addedSlots.removeAll(currentPartition.getSlotRanges());
        MasterSlaveEntry entry = getEntry(currentPartition.getSlotRanges().iterator().next());
        currentPartition.addSlotRanges(addedSlots);
        for (ClusterSlotRange slot : addedSlots) {
          entry.addSlotRange(slot);
          addEntry(slot, entry);
          log.info("{} slot added for {}", slot, entry.getClient().getAddr());
          lastPartitions.put(slot, currentPartition);
        }

        Set<ClusterSlotRange> removedSlots =
            new HashSet<ClusterSlotRange>(currentPartition.getSlotRanges());
        removedSlots.removeAll(newPartition.getSlotRanges());
        lastPartitions.keySet().removeAll(removedSlots);
        currentPartition.removeSlotRanges(removedSlots);

        for (ClusterSlotRange slot : removedSlots) {
          log.info("{} slot removed for {}", slot, entry.getClient().getAddr());
          entry.removeSlotRange(slot);
          removeMaster(slot);
        }
      }
    }
  }
  /**
   * Get the task Map which the task is alive and will be kept Only when type is
   * ASSIGN_TYPE_MONITOR, it is valid
   *
   * @param defaultContext
   * @param needAssigns
   * @return
   */
  public Map<Integer, ResourceAssignment> getKeepAssign(
      DefaultTopologyAssignContext defaultContext, Set<Integer> needAssigns) {

    Set<Integer> keepAssignIds = new HashSet<Integer>();
    keepAssignIds.addAll(defaultContext.getAllTaskIds());
    keepAssignIds.removeAll(defaultContext.getUnstoppedTaskIds());
    keepAssignIds.removeAll(needAssigns);

    Map<Integer, ResourceAssignment> keeps = new HashMap<Integer, ResourceAssignment>();
    if (keepAssignIds.isEmpty()) {
      return keeps;
    }

    Assignment oldAssignment = defaultContext.getOldAssignment();
    if (oldAssignment == null) {
      return keeps;
    }
    Map<Integer, ResourceAssignment> olds = oldAssignment.getTaskToResource();

    for (Integer task : keepAssignIds) {
      ResourceAssignment oldResource = olds.get(task);
      if (oldResource == null) {
        LOG.warn("No old assignment of " + task + ", " + defaultContext.toDetailString());
        continue;
      }

      keeps.put(task, oldResource);
    }

    return keeps;
  }
Пример #13
0
 /** @return the new constraints enforced at this handle, that aren't yet enforced at parents */
 public Set<PConstraint> getDeltaEnforcedConstraints() {
   Set<PConstraint> result = CollectionsFactory.getSet(); // new HashSet<PConstraint>(constraints);
   if (primaryParentStub != null) result.removeAll(primaryParentStub.getAllEnforcedConstraints());
   if (secondaryParentStub != null)
     result.removeAll(secondaryParentStub.getAllEnforcedConstraints());
   return result;
 }
Пример #14
0
 /** removeAll removes all elements from the given collection */
 public void testRemoveAll() {
   Set full = populatedSet(3);
   assertTrue(full.removeAll(Arrays.asList(one, two)));
   assertEquals(1, full.size());
   assertFalse(full.removeAll(Arrays.asList(one, two)));
   assertEquals(1, full.size());
 }
  private void walk(String authority, Path root, String prefix, int count) throws IOException {
    Path cachePath = BASE_PATH.resolve(authority);
    Path dirPath = Paths.get(cachePath.toString(), root.toString());

    Set<String> fileNames =
        Files.walk(dirPath)
            .filter(p -> p.toString().endsWith(".txt"))
            .map(p -> Paths.get(p.toAbsolutePath().toString()))
            .map(cachePath::relativize)
            .map(Object::toString)
            .collect(Collectors.toSet());
    assertFalse(fileNames.isEmpty());

    Set<String> expected =
        IntStream.range(0, count).mapToObj(i -> prefix + i + ".txt").collect(Collectors.toSet());
    assertFalse(expected.isEmpty());

    Set<String> extra = new HashSet<>(fileNames);
    extra.removeAll(expected);
    if (!extra.isEmpty()) {
      System.out.println("Extra entries " + extra);
    }
    assertTrue("Extra entries ", extra.isEmpty());

    Set<String> missing = new HashSet<>(expected);
    missing.removeAll(fileNames);
    if (!extra.isEmpty()) {
      System.out.println("Missing entries " + missing);
    }
    assertTrue("Missing entries", missing.isEmpty());
  }
Пример #16
0
  /**
   * Given a set of SCC nodes make this the lead member of the SCC and reroute all incoming and
   * outgoing links accordingly. This eager rewrite is based on the assumption that there are few
   * cycles so it is better to rewrite once and keep the graph easy to traverse.
   */
  public void makeLeadNodeFor(Set<GraphNode> members) {
    // Accumulate all successors
    Set<GraphNode> newSucc = new HashSet<>();
    Set<GraphNode> newSuccClosed = new HashSet<>();
    for (GraphNode n : members) {
      newSucc.addAll(n.succ);
      newSuccClosed.addAll(n.succClosed);
    }
    newSucc.removeAll(members);
    newSuccClosed.removeAll(members);
    succ = newSucc;
    succClosed = newSuccClosed;

    // Rewrite all direct successors to have us as predecessor
    for (GraphNode n : succ) {
      n.pred.removeAll(members);
      n.pred.add(this);
    }

    // Find all predecessor nodes and relink link them to point to us
    Set<GraphNode> done = new HashSet<>();
    Set<GraphNode> newAliases = new HashSet<>();
    for (GraphNode member : members) {
      addSiblings(newAliases, member);
    }
    becomeLeaderOf(newAliases);
    for (GraphNode n : members) {
      if (n != this) {
        pred.addAll(n.pred);
        n.relocateAllRefTo(this, done);
        n.becomeSubordinateOf(this);
      }
    }
    pred.removeAll(members);
  }
Пример #17
0
  public void testKeySetRemoveAllNullFromEmpty() {
    final Map<K, V> map;
    try {
      map = makeEmptyMap();
    } catch (UnsupportedOperationException e) {
      return;
    }

    Set<K> keySet = map.keySet();
    if (supportsRemove) {
      try {
        keySet.removeAll(null);
        fail("Expected NullPointerException.");
      } catch (NullPointerException e) {
        // Expected.
      }
    } else {
      try {
        keySet.removeAll(null);
        fail("Expected UnsupportedOperationException or NullPointerException.");
      } catch (UnsupportedOperationException e) {
        // Expected.
      } catch (NullPointerException e) {
        // Expected.
      }
    }
    assertInvariants(map);
  }
 private final synchronized List<? extends PathResourceImplementation> refresh() {
   List<Dependency> l = getDeps().all();
   Set<DependencyPathResourceImplementation> old;
   Set<DependencyPathResourceImplementation> nue;
   synchronized (this) {
     old = new TreeSet<DependencyPathResourceImplementation>(resources);
     nue = new TreeSet<DependencyPathResourceImplementation>();
     for (int i = 0; i < l.size(); i++) {
       nue.add(new DependencyPathResourceImplementation(l.get(i), i));
     }
     if (resources.equals(nue)) {
       return new ArrayList<PathResourceImplementation>(resources);
     }
     Set<DependencyPathResourceImplementation> removed =
         new HashSet<DependencyPathResourceImplementation>(old);
     removed.removeAll(nue);
     Set<DependencyPathResourceImplementation> added =
         new HashSet<DependencyPathResourceImplementation>(nue);
     added.removeAll(old);
     for (DependencyPathResourceImplementation d : removed) {
       resources.remove(d);
     }
     for (DependencyPathResourceImplementation d : added) {
       resources.add(d);
     }
   }
   List<? extends PathResourceImplementation> result =
       new ArrayList<PathResourceImplementation>(nue);
   fire(ClassPathImplementation.PROP_RESOURCES, old, result);
   return result;
 }
Пример #19
0
  // /////////////////////////////////////////////////////////////////
  // // private methods ////
  // Recursively compute the set of free variables for all actors
  // deeply contained in the given model.
  private Set _freeVariables(Entity model) throws IllegalActionException {
    // First get the free variables of contained actors.
    Set set = new HashSet();

    if (model instanceof CompositeEntity) {
      for (Iterator entities = ((CompositeEntity) model).entityList().iterator();
          entities.hasNext(); ) {
        Entity entity = (Entity) entities.next();
        set.addAll(_freeVariables(entity));
      }
    }

    // Next, compute the set of variable names defined in this container.
    Set variableNames = new HashSet();

    for (Iterator variables = model.attributeList(Variable.class).iterator();
        variables.hasNext(); ) {
      Variable variable = (Variable) variables.next();
      variableNames.add(variable.getName());
    }

    variableNames = Collections.unmodifiableSet(variableNames);

    // Free variables of contained actors that are defined in this
    // container are not free variables of this container.
    set.removeAll(variableNames);

    // Iterate over all the variables of this container, and add in
    // any free variables they reference.
    PtParser parser = new PtParser();
    ParseTreeFreeVariableCollector collector = new ParseTreeFreeVariableCollector();

    for (Iterator variables = model.attributeList(Variable.class).iterator();
        variables.hasNext(); ) {
      Variable variable = (Variable) variables.next();
      String expression = variable.getExpression();
      ASTPtRootNode root;

      if (variable.isStringMode()) {
        root = parser.generateStringParseTree(expression);
      } else {
        root = parser.generateParseTree(expression);
      }

      Set freeIdentifiers = new HashSet(collector.collectFreeVariables(root));

      // Identifiers that reference other variables in the same container
      // are bound, not free.
      Set tempSet = new HashSet(variableNames);
      tempSet.remove(variable.getName());
      freeIdentifiers.removeAll(tempSet);

      set.addAll(freeIdentifiers);
    }

    _entityToFreeVariableNameSet.put(model, set);
    return set;
  }
 protected static Set<String> computeKeywords(Grammar grammar) {
   Set<String> keywords = new HashSet<String>(GrammarUtil.getAllKeywords(grammar));
   keywords.removeAll(getAllKeywords(grammar, "UnrestrictedName"));
   keywords.removeAll(getAllKeywords(grammar, "EssentialOCLReservedKeyword"));
   keywords.removeAll(getAllKeywords(grammar, "RestrictedKeywords"));
   keywords.removeAll(getAllKeywords(grammar, "CollectionTypeIdentifier"));
   keywords.removeAll(getAllKeywords(grammar, "PrimitiveTypeIdentifier"));
   return keywords;
 }
Пример #21
0
  /**
   * Update the underlying connectiosStore.
   *
   * @param oldElement - old element
   * @param newElement - new element
   * @throws Exception
   */
  protected void updateConnectionStore(E oldElement, E newElement) throws Exception {
    if (rollingEnabled && oldElement == null) {
      rollingTypeahead.offer(newElement);
    } else {
      long scn = newElement.getTimestamp();
      int elemId = newElement.getElementId();

      if (oldElement == null) {
        // Insert operation
        for (String term : newElement.getTerms()) {
          int len = Math.min(term.length(), maxKeyLength);
          for (int i = 1; i <= len; i++) {
            String source = term.substring(0, i);
            connectionsStore.addConnection(source, elemId, scn);
          }
        }
      } else if (newElement.getTimestamp() >= getHWMark()) {
        // Update operation
        Set<String> oldPrefixes = new HashSet<String>();
        Set<String> newPrefixes = new HashSet<String>();

        for (String term : oldElement.getTerms()) {
          int len = Math.min(term.length(), maxKeyLength);
          for (int i = 1; i <= len; i++) {
            String source = term.substring(0, i);
            oldPrefixes.add(source);
          }
        }

        for (String term : newElement.getTerms()) {
          int len = Math.min(term.length(), maxKeyLength);
          for (int i = 1; i <= len; i++) {
            String source = term.substring(0, i);
            newPrefixes.add(source);
          }
        }

        // Calculate intersection
        Set<String> commonPrefixes = new HashSet<String>();
        commonPrefixes.addAll(oldPrefixes);
        commonPrefixes.retainAll(newPrefixes);

        newPrefixes.removeAll(commonPrefixes);
        for (String source : newPrefixes) {
          connectionsStore.addConnection(source, elemId, scn);
        }

        oldPrefixes.removeAll(commonPrefixes);
        for (String source : oldPrefixes) {
          connectionsStore.removeConnection(source, elemId, scn);
        }
      } else {
        logger.info("ignored element: " + newElement);
      }
    }
  }
  private void scan() throws OperationFailedException {

    try {
      scanLock.lockInterruptibly();
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      return;
    }
    try {
      if (scanEnabled) { // confirm the scan is still wanted

        log.tracef(
            "Scanning directory %s for deployment content changes",
            deploymentDir.getAbsolutePath());

        final List<ModelNode> updates = new ArrayList<ModelNode>();

        Map<String, File> foundDeployed = new HashMap<String, File>();
        Set<String> newlyAdded = new HashSet<String>();
        Set<String> registeredDeployments = getDeploymentNames();
        scanDirectory(deploymentDir, updates, foundDeployed, newlyAdded, registeredDeployments);

        // Add remove actions to the plan for anything we count as
        // deployed that we didn't find on the scan
        Set<String> toRemove = new HashSet<String>(deployed);
        toRemove.removeAll(foundDeployed.keySet());
        toRemove.removeAll(newlyAdded); // in case user removed the marker and added replacement
        for (String missing : toRemove) {
          updates.add(getUndeployOperation(missing));
          updates.add(getRemoveOperation(missing));
        }

        if (updates.size() > 0) {
          if (log.isDebugEnabled()) {
            for (ModelNode update : updates) {
              log.debugf("Deployment scan of [%s] found update action [%s]", deploymentDir, update);
            }
          }
          Operation composite = getCompositeUpdate(updates);
          ModelNode results = serverController.execute(composite);
          //                    System.out.println(composite);
          //                    System.out.println(results);
          // FIXME deal with result
        }

        // Throw away any found marker files that we didn't already know about
        Set<String> validFinds = cleanSpuriousMarkerFiles(foundDeployed);
        validFinds.addAll(newlyAdded);
        this.deployed = validFinds;

        log.tracef("Scan complete");
      }
    } finally {
      scanLock.unlock();
    }
  }
Пример #23
0
 /**
  * Get all users that don't have any special status in this channel. This means that they aren't
  * ops, have voice, superops, halops, or owners in this channel
  *
  * @return An <i>unmodifiable</i> Set (IE snapshot) of non-special users in the channel
  */
 public Set<User> getNormalUsers() {
   // Build set
   Set<User> normalUsers = new HashSet<User>(bot.getUsers(this));
   normalUsers.removeAll(ops);
   normalUsers.removeAll(voices);
   normalUsers.removeAll(halfOps);
   normalUsers.removeAll(superOps);
   normalUsers.removeAll(owners);
   return Collections.unmodifiableSet(normalUsers);
 }
Пример #24
0
  /**
   * Finds set of all defs in function given (defSites). Adds parameters of function to this set:
   * defSites. Finds all variables that are referenced in the function given (alf.names).
   * windowProps are all global properties available. Closures = alf.names - defSites - windowProps
   *
   * @param n root node of the function who's closures are to be found
   * @return set of closure names
   */
  private Set<String> findClosures(Node n) {
    Set<String> closureVars = null;

    SimpleDefinitionFinder defFinder = new SimpleDefinitionFinder(compiler);
    defFinder.process(externs, n.getLastChild());
    Collection<DefinitionSite> defSites = defFinder.getDefinitionSites();
    Set<String> localDefs = new HashSet<String>();

    for (DefinitionSite site : defSites) {
      if (site.node.getType() == Token.GETPROP) continue;
      String def = site.node.getString();
      if (def.length() > 0) {
        localDefs.add(def);
      }
    }

    // adding params to function as defs
    Node origParamNode = n.getChildAtIndex(1);
    for (int i = 0; i < origParamNode.getChildCount(); i++) {
      String temp = origParamNode.getChildAtIndex(i).getString();
      localDefs.add(temp);
    }

    // System.out.println("\nPrinting LOCAL def sites:" + defs);

    /*SimpleDefinitionFinder defFinder1 = new SimpleDefinitionFinder(compiler);
    defFinder1.process(externs, root);
    Collection<DefinitionSite> defSites1 = defFinder1.getDefinitionSites();
    Set<String> defs1 = new HashSet<String>();

    for(DefinitionSite site1: defSites1){
    	if (site1.node.getType() == Token.GETPROP) continue;
    	String def = site1.node.getString();
    	if (def.length() > 0){
    		defs1.add(def);
    	}
    }
    System.out.println("\nPrinting Global def sites:" + defs1);*/

    AllNamesFinder alf = new AllNamesFinder(compiler);
    NodeTraversal.traverse(compiler, n.getLastChild(), alf);

    // System.out.println("all names: " + alf.names);

    closureVars = alf.names;

    closureVars.removeAll(localDefs);
    closureVars.removeAll(Props.windowProps);

    closureVars.remove(
        "this"); // since 'this' is later modified to $$_self we don't need to consider this as
    // closure

    return closureVars;
  }
  private void checkSlotsChange(
      ClusterServersConfig cfg, Collection<ClusterPartition> newPartitions) {
    checkSlotsMigration(newPartitions);

    Collection<ClusterSlotRange> newPartitionsSlots = slots(newPartitions);
    Set<ClusterSlotRange> removedSlots = new HashSet<ClusterSlotRange>(lastPartitions.keySet());
    removedSlots.removeAll(newPartitionsSlots);
    lastPartitions.keySet().removeAll(removedSlots);
    if (!removedSlots.isEmpty()) {
      log.info("{} slot ranges found to remove", removedSlots);
    }

    for (ClusterSlotRange slot : removedSlots) {
      MasterSlaveEntry entry = removeMaster(slot);
      entry.removeSlotRange(slot);
      if (entry.getSlotRanges().isEmpty()) {
        entry.shutdownMasterAsync();
        log.info("{} master and slaves for it removed", entry.getClient().getAddr());
      }
    }

    Set<ClusterSlotRange> addedSlots = new HashSet<ClusterSlotRange>(newPartitionsSlots);
    addedSlots.removeAll(lastPartitions.keySet());
    if (!addedSlots.isEmpty()) {
      log.info("{} slots found to add", addedSlots);
    }
    for (final ClusterSlotRange slot : addedSlots) {
      ClusterPartition partition = find(newPartitions, slot);
      boolean masterFound = false;
      for (MasterSlaveEntry entry : getEntries().values()) {
        if (entry.getClient().getAddr().equals(partition.getMasterAddr())) {
          addEntry(slot, entry);
          lastPartitions.put(slot, partition);
          masterFound = true;
          break;
        }
      }
      if (!masterFound) {
        Future<Collection<Future<Void>>> future = addMasterEntry(partition, cfg);
        future.addListener(
            new FutureListener<Collection<Future<Void>>>() {
              @Override
              public void operationComplete(Future<Collection<Future<Void>>> future)
                  throws Exception {
                if (!future.isSuccess()) {
                  log.error(
                      "New cluster slot range " + slot + " without master node detected",
                      future.cause());
                }
              }
            });
      }
    }
  }
  /**
   * removeNoise() methods removes inconsistent data and missing values. For consistency where are
   * there are reviews relevant and non relevant for each item are considered.
   */
  private void removeNoise() {
    Set<String> nonRel = itemUserMatrixNonRelevant.keySet();
    Set<String> rel = itemUserMatrixRelevant.keySet();
    Set<String> noise = new LinkedHashSet<String>(rel);
    Set<String> iter = new LinkedHashSet<String>(rel);
    Set<String> niter = new LinkedHashSet<String>(nonRel);
    noise.retainAll(nonRel);
    iter.removeAll(noise);
    niter.removeAll(noise);
    System.out.println(userItemMatrix.size());
    System.out.println(userItemMatrixRelevant.size());
    System.out.println(itemUserMatrixRelevant.size());
    System.out.println(itemUserMatrixNonRelevant.size());

    for (String unwanted : iter) {
      itemUserMatrixRelevant.remove(unwanted);
      itemUserMatrixNonRelevant.remove(unwanted);
    }

    for (Entry<String, ArrayList<String>> entry : userItemMatrix.entrySet()) {
      entry.getValue().removeAll(iter);
    }
    for (Entry<String, ArrayList<String>> entry : userItemMatrixRelevant.entrySet()) {
      entry.getValue().removeAll(iter);
    }

    for (String unwanted : niter) {
      itemUserMatrixRelevant.remove(unwanted);
      itemUserMatrixNonRelevant.remove(unwanted);
    }

    for (Entry<String, ArrayList<String>> entry : userItemMatrix.entrySet()) {
      entry.getValue().removeAll(niter);
    }
    for (Entry<String, ArrayList<String>> entry : userItemMatrixRelevant.entrySet()) {
      entry.getValue().removeAll(niter);
    }

    System.out.println(userItemMatrix.size());
    System.out.println(userItemMatrixRelevant.size());
    System.out.println(itemUserMatrixRelevant.size());
    System.out.println(itemUserMatrixNonRelevant.size());

    int maxSize = 0;
    String userid = "";
    for (Entry<String, ArrayList<String>> entry : userItemMatrixRelevant.entrySet()) {
      if (entry.getValue().size() > maxSize) {
        maxSize = entry.getValue().size();
        userid = entry.getKey();
      }
    }
    System.out.println("Choose user " + userid);
  }
Пример #27
0
  private void doUpdateModelsSet() {
    assertCanChange();

    for (SModel model : getModels()) {
      if (model instanceof EditableSModel && ((EditableSModel) model).isChanged()) {
        LOG.warn(
            "Trying to reload module "
                + getModuleName()
                + " which contains a non-saved model '"
                + model.getName()
                + "'. To prevent data loss, MPS will not update models in this module. "
                + "Please save your work and restart MPS. See MPS-18743 for details.");
        return;
      }
    }

    Set<ModelRoot> toRemove = new HashSet<ModelRoot>(mySModelRoots);
    Set<ModelRoot> toUpdate = new HashSet<ModelRoot>(mySModelRoots);
    Set<ModelRoot> toAttach = new HashSet<ModelRoot>();

    for (ModelRoot root : loadRoots()) {
      try {
        if (mySModelRoots.contains(root)) {
          toRemove.remove(root);
        } else {
          toAttach.add(root);
        }
      } catch (Exception e) {
        LOG.error(
            "Error loading models from root `"
                + root.getPresentation()
                + "'. Requested by: "
                + this,
            e);
      }
    }
    toUpdate.removeAll(toRemove);

    for (ModelRoot modelRoot : toRemove) {
      ((ModelRootBase) modelRoot).dispose();
    }
    mySModelRoots.removeAll(toRemove);
    for (ModelRoot modelRoot : toAttach) {
      ModelRootBase rootBase = (ModelRootBase) modelRoot;
      rootBase.setModule(this);
      mySModelRoots.add(modelRoot);
      rootBase.attach();
    }
    for (ModelRoot modelRoot : toUpdate) {
      ((ModelRootBase) modelRoot).update();
    }
  }
 public synchronized void assertAllEqual(int expectedCount) throws IOException {
   Set<Uid> primaryIds = getShardDocUIDs(primary);
   assertThat(primaryIds.size(), equalTo(expectedCount));
   for (IndexShard replica : replicas) {
     Set<Uid> replicaIds = getShardDocUIDs(replica);
     Set<Uid> temp = new HashSet<>(primaryIds);
     temp.removeAll(replicaIds);
     assertThat(replica.routingEntry() + " is missing docs", temp, empty());
     temp = new HashSet<>(replicaIds);
     temp.removeAll(primaryIds);
     assertThat(replica.routingEntry() + " has extra docs", temp, empty());
   }
 }
Пример #29
0
  private void checkAllArticlesAreAllocatedOrReversed(
      Collection<? extends Article> deletedArticles) {
    ArticleStatusCheckResult articleStatusCheckResult =
        new ArticleStatusCheckResult(getArticleContainerEdit().getArticles());

    articlesWithWrongState.addAll(articleStatusCheckResult.getNotAllocatedNorReversedArticles());
    articlesWithWrongState.removeAll(articleStatusCheckResult.getAllocatedOrReversedArticles());

    if (deletedArticles != null) articlesWithWrongState.removeAll(deletedArticles);

    if (buttonComp != null && !buttonComp.isDisposed())
      buttonComp.setEnabled(articlesWithWrongState.isEmpty());
  }
Пример #30
0
  @Override
  public void set(
      final SecurityContext securityContext,
      final NodeInterface targetNode,
      final Iterable<S> collection)
      throws FrameworkException {

    final App app = StructrApp.getInstance(securityContext);
    final Set<S> toBeDeleted =
        new LinkedHashSet<>(Iterables.toList(get(securityContext, targetNode, null)));
    final Set<S> toBeCreated = new LinkedHashSet<>();

    if (collection != null) {
      Iterables.addAll(toBeCreated, collection);
    }

    // create intersection of both sets
    final Set<S> intersection = new LinkedHashSet<>(toBeCreated);
    intersection.retainAll(toBeDeleted);

    // intersection needs no change
    toBeCreated.removeAll(intersection);
    toBeDeleted.removeAll(intersection);

    // remove existing relationships
    for (S sourceNode : toBeDeleted) {

      for (AbstractRelationship rel : targetNode.getIncomingRelationships()) {

        final String relTypeName = rel.getRelType().name();
        final String desiredRelType = relation.name();

        if (relTypeName.equals(desiredRelType) && rel.getSourceNode().equals(sourceNode)) {

          app.delete(rel);
        }
      }
    }

    // create new relationships
    for (S sourceNode : toBeCreated) {

      relation.ensureCardinality(securityContext, sourceNode, targetNode);

      app.create(
          sourceNode,
          targetNode,
          relation.getClass(),
          getNotionProperties(securityContext, relation.getClass(), sourceNode.getUuid()));
    }
  }