List of usage examples for com.google.common.collect MapDifference entriesDiffering
Map<K, ValueDifference<V>> entriesDiffering();
From source file:org.wso2.carbon.governance.comparator.wsdl.WSDLServicesComparator.java
protected void compareServices(Definition base, Definition changed, DefaultComparison comparison) { DefaultComparison.DefaultSection section = null; Map<QName, Service> baseService = base.getAllServices(); Map<QName, Service> changedService = changed.getAllServices(); MapDifference<QName, Service> mapDiff = Maps.difference(baseService, changedService); //If both side services are equal, return if (mapDiff.areEqual()) { return;/*from w w w . j a v a 2s. c om*/ } Map<QName, Service> additions = mapDiff.entriesOnlyOnRight(); if (section == null && additions.size() > 0) { section = comparison.newSection(); } processAdditions(section, additions, changed); Map<QName, Service> removals = mapDiff.entriesOnlyOnLeft(); if (section == null && removals.size() > 0) { section = comparison.newSection(); } processRemovals(section, removals, base); Map<QName, MapDifference.ValueDifference<Service>> changes = mapDiff.entriesDiffering(); section = processChanges(section, comparison, changes, base, changed); if (section != null) { comparison.addSection(ComparatorConstants.WSDL_SERVICE, section); } }
From source file:org.sonarsource.sonarlint.core.container.connected.update.check.GlobalSettingsUpdateChecker.java
public void checkForUpdates(String serverVersion, DefaultStorageUpdateCheckResult result) { GlobalProperties serverGlobalProperties = globalPropertiesDownloader.fetchGlobalSettings(serverVersion); GlobalProperties storageGlobalProperties = storageManager.readGlobalPropertiesFromStorage(); MapDifference<String, String> propDiff = Maps.difference(filter(storageGlobalProperties.getPropertiesMap()), filter(serverGlobalProperties.getPropertiesMap())); if (!propDiff.areEqual()) { result.appendToChangelog("Global settings updated"); for (Map.Entry<String, String> entry : propDiff.entriesOnlyOnLeft().entrySet()) { LOG.debug("Property '{}' removed", entry.getKey()); }/*from www. j a va 2s . c om*/ for (Map.Entry<String, String> entry : propDiff.entriesOnlyOnRight().entrySet()) { LOG.debug("Property '{}' added with value '{}'", entry.getKey(), formatValue(entry.getKey(), entry.getValue())); } for (Map.Entry<String, ValueDifference<String>> entry : propDiff.entriesDiffering().entrySet()) { LOG.debug("Value of property '{}' changed from '{}' to '{}'", entry.getKey(), formatLeftDiff(entry.getKey(), entry.getValue().leftValue(), entry.getValue().rightValue()), formatRightDiff(entry.getKey(), entry.getValue().leftValue(), entry.getValue().rightValue())); } } }
From source file:com.addthis.hydra.job.alert.JobAlertRunner.java
/** * Iterate over alert map, checking the status of each alert and sending emails as needed. *///from w w w .java 2 s. com public void scanAlerts() { if (alertsEnabled) { log.info("Started alert scan of {} alerts...", alertMap.size()); try { for (Map.Entry<String, AbstractJobAlert> entry : alertMap.entrySet()) { AbstractJobAlert oldAlert = entry.getValue(); Map<String, String> currentErrors = oldAlert.getActiveJobs(); // entry may be concurrently deleted, so only recompute if still present, and while locked AbstractJobAlert alert = alertMap.computeIfPresent(entry.getKey(), (id, currentAlert) -> { currentAlert.checkAlertForJobs(currentAlert.getAlertJobs(spawn), meshyClient); if (!currentAlert.getActiveJobs().equals(currentErrors)) { storeAlert(currentAlert.alertId, currentAlert); } return currentAlert; }); // null if it was concurrently removed from the map. Does not catch all removals, but might as well // make a best effort attempt to send clears when convenient (should probably move clear emails to // the removal method at some point) if (alert == null) { emailAlert(oldAlert, "[CLEAR] ", currentErrors); } else { Map<String, String> newErrors = alert.getActiveJobs(); MapDifference<String, String> difference = Maps.difference(currentErrors, newErrors); emailAlert(oldAlert, "[CLEAR] ", difference.entriesOnlyOnLeft()); emailAlert(alert, "[TRIGGER] ", difference.entriesOnlyOnRight()); Map<String, String> errorsChanged = new HashMap<>(); for (Map.Entry<String, MapDifference.ValueDifference<String>> differing : difference .entriesDiffering().entrySet()) { String oldValue = differing.getValue().leftValue(); String newValue = differing.getValue().rightValue(); if (!alert.suppressChanges.suppress(oldValue, newValue)) { errorsChanged.put(differing.getKey(), newValue); } } emailAlert(alert, "[ERROR CHANGED] ", errorsChanged); } } lastAlertScanFailed = false; log.info("Finished alert scan"); } catch (Exception e) { lastAlertScanFailed = true; log.error("Unexpected error while scanning alerts: {}", e.getMessage(), e); } } }
From source file:org.wso2.carbon.governance.comparator.wsdl.WSDLImportsComparator.java
protected void compareImports(Map<String, Vector<Import>> base, Map<String, Vector<Import>> changed, DefaultComparison comparison) {/*from ww w . j a v a2s . com*/ DefaultComparison.DefaultSection section = null; MapDifference<String, Vector<Import>> mapDiff = Maps.difference(base, changed); //If both side imports are equal, return if (mapDiff.areEqual()) { return; } Map<String, Vector<Import>> additions = mapDiff.entriesOnlyOnRight(); if (section == null && additions.size() > 0) { section = comparison.newSection(); } processAdditions(comparison, section, additions); Map<String, Vector<Import>> removals = mapDiff.entriesOnlyOnLeft(); if (section == null && removals.size() > 0) { section = comparison.newSection(); } processRemovals(comparison, section, removals); Map<String, MapDifference.ValueDifference<Vector<Import>>> changes = mapDiff.entriesDiffering(); if (section == null && changes.size() > 0) { section = comparison.newSection(); } processChanges(comparison, section, changes); if (section != null) { comparison.addSection(ComparatorConstants.WSDL_IMPORTS, section); } }
From source file:org.wso2.carbon.governance.comparator.wsdl.WSDLPortComparator.java
protected void comparePorts(Definition base, Definition changed, DefaultComparison comparison) { DefaultComparison.DefaultSection section = null; Set<QName> commonKeys = Sets.intersection(base.getAllServices().keySet(), changed.getAllServices().keySet()); if (commonKeys.size() > 0) { for (QName service : commonKeys) { Map<QName, Port> basePorts = base.getService(service).getPorts(); Map<QName, Port> changedPorts = changed.getService(service).getPorts(); MapDifference<QName, Port> mapDiff = Maps.difference(basePorts, changedPorts); if (!mapDiff.areEqual()) { Map<QName, Port> additions = mapDiff.entriesOnlyOnRight(); if (section == null && additions.size() > 0) { section = comparison.newSection(); }/*from w w w .j av a 2s . c om*/ processAdditions(section, additions, changed); Map<QName, Port> removals = mapDiff.entriesOnlyOnLeft(); if (section == null && removals.size() > 0) { section = comparison.newSection(); } processRemovals(section, removals, base); Map<QName, MapDifference.ValueDifference<Port>> changes = mapDiff.entriesDiffering(); section = processChanges(section, comparison, changes, base, changed); } } } if (section != null) { comparison.addSection(ComparatorConstants.WSDL_PORTS, section); } }
From source file:com.facebook.buck.parser.DaemonicParserState.java
private synchronized void invalidateIfBuckConfigOrEnvHasChanged(Cell cell, Path buildFile) { try (AutoCloseableLock readLock = cellStateLock.readLock()) { DaemonicCellState state = cellPathToDaemonicState.get(cell.getRoot()); if (state == null) { return; }/*ww w . j a v a 2 s .co m*/ // Invalidates and also keeps the state cell up-to-date state.invalidateIfBuckConfigHasChanged(cell, buildFile); Optional<MapDifference<String, String>> envDiff = state.invalidateIfEnvHasChanged(cell, buildFile); if (envDiff.isPresent()) { MapDifference<String, String> diff = envDiff.get(); LOG.warn("Invalidating cache on environment change (%s)", diff); Set<String> environmentChanges = new HashSet<>(); environmentChanges.addAll(diff.entriesOnlyOnLeft().keySet()); environmentChanges.addAll(diff.entriesOnlyOnRight().keySet()); environmentChanges.addAll(diff.entriesDiffering().keySet()); cacheInvalidatedByEnvironmentVariableChangeCounter.addAll(environmentChanges); broadcastEventListener.broadcast(ParsingEvent.environmentalChange(environmentChanges.toString())); } } }
From source file:co.cask.cdap.internal.app.deploy.pipeline.CreateSchedulesStage.java
@Override public void process(ApplicationWithPrograms input) throws Exception { ApplicationSpecification existingAppSpec = input.getExistingAppSpecification(); Map<String, ScheduleSpecification> existingSchedulesMap; if (existingAppSpec == null) { existingSchedulesMap = ImmutableMap.of(); } else {/* w w w . j a va 2 s. c om*/ existingSchedulesMap = existingAppSpec.getSchedules(); } MapDifference<String, ScheduleSpecification> mapDiff = Maps.difference(existingSchedulesMap, input.getSpecification().getSchedules()); for (Map.Entry<String, ScheduleSpecification> entry : mapDiff.entriesOnlyOnLeft().entrySet()) { // delete schedules that existed in the old app spec, but don't anymore ScheduleSpecification scheduleSpec = entry.getValue(); ProgramType programType = ProgramType .valueOfSchedulableType(scheduleSpec.getProgram().getProgramType()); scheduler.deleteSchedule( Id.Program.from(input.getId(), programType, scheduleSpec.getProgram().getProgramName()), scheduleSpec.getProgram().getProgramType(), scheduleSpec.getSchedule().getName()); } for (Map.Entry<String, MapDifference.ValueDifference<ScheduleSpecification>> entry : mapDiff .entriesDiffering().entrySet()) { // Update those schedules - the new schedules have the same IDs but different specs ScheduleSpecification newScheduleSpec = entry.getValue().rightValue(); ScheduleSpecification oldScheduleSpec = entry.getValue().leftValue(); if (newScheduleSpec.getSchedule().equals(oldScheduleSpec.getSchedule())) { // The schedules are exactly the same - the difference in spec might come from the properties map - // hence it is useless to update the schedule continue; } ProgramType programType = ProgramType .valueOfSchedulableType(newScheduleSpec.getProgram().getProgramType()); scheduler.updateSchedule( Id.Program.from(input.getId(), programType, newScheduleSpec.getProgram().getProgramName()), newScheduleSpec.getProgram().getProgramType(), newScheduleSpec.getSchedule()); } for (Map.Entry<String, ScheduleSpecification> entry : mapDiff.entriesOnlyOnRight().entrySet()) { ScheduleSpecification scheduleSpec = entry.getValue(); ProgramType programType = ProgramType .valueOfSchedulableType(scheduleSpec.getProgram().getProgramType()); scheduler.schedule( Id.Program.from(input.getId(), programType, scheduleSpec.getProgram().getProgramName()), scheduleSpec.getProgram().getProgramType(), scheduleSpec.getSchedule()); } // Note: the mapDiff also has a entriesInCommon method returning all entries in left and right maps // which have exactly the same keys and values. In that case, we don't need to do anything, not // even to update the schedule // Emit the input to next stage. emit(input); }
From source file:org.terasology.identity.storageServiceClient.SyncIdentitiesAction.java
@Override public void perform(StorageServiceWorker worker) { if (worker.hasConflictingIdentities()) { worker.logMessage(true, "${engine:menu#storage-service-sync-previous-conflicts}"); } else {/* w w w. j a v a 2 s .co m*/ try { Map<PublicIdentityCertificate, ClientIdentity> local = worker.securityConfig.getAllIdentities(); Map<PublicIdentityCertificate, ClientIdentity> remote = worker.sessionInstance.getAllIdentities(); MapDifference<PublicIdentityCertificate, ClientIdentity> diff = Maps.difference(local, remote); //upload the "local only" ones for (Map.Entry<PublicIdentityCertificate, ClientIdentity> entry : diff.entriesOnlyOnLeft() .entrySet()) { if (entry.getValue().getPlayerPrivateCertificate() != null) { //TODO: find out why sometimes it's null worker.sessionInstance.putIdentity(entry.getKey(), entry.getValue()); } } //download the "remote only" ones for (Map.Entry<PublicIdentityCertificate, ClientIdentity> entry : diff.entriesOnlyOnRight() .entrySet()) { worker.securityConfig.addIdentity(entry.getKey(), entry.getValue()); } //keep track of the conflicting ones for manual resolution worker.resetConflicts(); for (Map.Entry<PublicIdentityCertificate, MapDifference.ValueDifference<ClientIdentity>> entry : diff .entriesDiffering().entrySet()) { worker.conflictingRemoteIdentities .addLast(new IdentityBundle(entry.getKey(), entry.getValue().rightValue())); } worker.saveConfig(); worker.logMessage(false, "${engine:menu#storage-service-sync-ok}", diff.entriesOnlyOnRight().size(), diff.entriesOnlyOnLeft().size(), diff.entriesDiffering().size()); if (!diff.entriesDiffering().isEmpty()) { worker.logMessage(true, "${engine:menu#storage-service-sync-conflicts}"); } } catch (Exception e) { worker.logMessage(true, "${engine:menu#storage-service-sync-fail}", e.getMessage()); } } worker.status = StorageServiceWorkerStatus.LOGGED_IN; }
From source file:org.apache.cassandra.schema.LegacySchemaTables.java
public static Mutation makeUpdateTableMutation(KSMetaData keyspace, CFMetaData oldTable, CFMetaData newTable, long timestamp, boolean fromThrift) { Mutation mutation = makeCreateKeyspaceMutation(keyspace, timestamp, false); addTableToSchemaMutation(newTable, timestamp, false, mutation); MapDifference<ByteBuffer, ColumnDefinition> columnDiff = Maps.difference(oldTable.getColumnMetadata(), newTable.getColumnMetadata()); // columns that are no longer needed for (ColumnDefinition column : columnDiff.entriesOnlyOnLeft().values()) { // Thrift only knows about the REGULAR ColumnDefinition type, so don't consider other type // are being deleted just because they are not here. if (fromThrift && column.kind != ColumnDefinition.Kind.REGULAR) continue; dropColumnFromSchemaMutation(oldTable, column, timestamp, mutation); }//from w ww . j av a 2s. com // newly added columns for (ColumnDefinition column : columnDiff.entriesOnlyOnRight().values()) addColumnToSchemaMutation(newTable, column, timestamp, mutation); // old columns with updated attributes for (ByteBuffer name : columnDiff.entriesDiffering().keySet()) addColumnToSchemaMutation(newTable, newTable.getColumnDefinition(name), timestamp, mutation); MapDifference<String, TriggerDefinition> triggerDiff = Maps.difference(oldTable.getTriggers(), newTable.getTriggers()); // dropped triggers for (TriggerDefinition trigger : triggerDiff.entriesOnlyOnLeft().values()) dropTriggerFromSchemaMutation(oldTable, trigger, timestamp, mutation); // newly created triggers for (TriggerDefinition trigger : triggerDiff.entriesOnlyOnRight().values()) addTriggerToSchemaMutation(newTable, trigger, timestamp, mutation); return mutation; }
From source file:org.onosproject.store.consistent.impl.DistributedLeadershipManager.java
private void refreshLeaderBoard() { try {/*from ww w . j a va 2 s . co m*/ Map<String, Leadership> newLeaderBoard = Maps.newHashMap(); leaderMap.entrySet().forEach(entry -> { String path = entry.getKey(); Versioned<NodeId> leader = entry.getValue(); Leadership leadership = new Leadership(path, leader.value(), leader.version(), leader.creationTime()); newLeaderBoard.put(path, leadership); }); // first take snapshot of current leader board. Map<String, Leadership> currentLeaderBoard = ImmutableMap.copyOf(leaderBoard); MapDifference<String, Leadership> diff = Maps.difference(currentLeaderBoard, newLeaderBoard); // evict stale leaders diff.entriesOnlyOnLeft().forEach((path, leadership) -> { log.debug("Evicting {} from leaderboard. It is no longer active leader.", leadership); onLeadershipEvent(new LeadershipEvent(LeadershipEvent.Type.LEADER_BOOTED, leadership)); }); // add missing leaders diff.entriesOnlyOnRight().forEach((path, leadership) -> { log.debug("Adding {} to leaderboard. It is now the active leader.", leadership); onLeadershipEvent(new LeadershipEvent(LeadershipEvent.Type.LEADER_ELECTED, leadership)); }); // add updated leaders diff.entriesDiffering().forEach((path, difference) -> { Leadership current = difference.leftValue(); Leadership updated = difference.rightValue(); if (current.epoch() < updated.epoch()) { log.debug("Updated {} in leaderboard.", updated); onLeadershipEvent(new LeadershipEvent(LeadershipEvent.Type.LEADER_ELECTED, updated)); } }); } catch (Exception e) { log.debug("Failed to refresh leader board", e); } }