@Override public boolean reconcileAgentExternalCredentials(Agent agent, Account account, Map<String, Long> externalLinks, Map<String, ExternalProject> projects, Map<Long, Region> regionsIds, Map<String, Region> regionNameToRegion) { Region localRegion = null; for (Region region : regionsIds.values()) { if (region.getLocal()) { localRegion = region; } } boolean success = true; // 2. Reconcile agent's credentials try { reconcileExternalCredentials(account, agent, localRegion, externalLinks, projects, regionNameToRegion); } catch (Exception ex) { success = false; log.error(String.format("Fail to reconcile credentials for agent [%d]", agent.getId()), ex); } return success; }
@Override public void doWithLockNoResult() { List<Region> regions = objectManager.find(Region.class, REGION.REMOVED, new Condition(ConditionType.NULL)); if (regions.size() == 0) { return; } Account localAccount = objectManager.loadResource(Account.class, accountId); if (INVALID_STATES.contains(localAccount.getState())) { return; } Map<String, Region> regionsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); Region localRegion = null; for (Region region : regions) { regionsMap.put(region.getName(), region); if (region.getLocal()) { localRegion = region; } } List<AccountLink> toRemove = new ArrayList<>(); List<AccountLink> toUpdate = new ArrayList<>(); Set<String> toCreate = new HashSet<>(); fetchAccountLinks(accountId, regionsMap, localRegion, toRemove, toUpdate, toCreate); reconcileAccountLinks(accountId, regionsMap, toRemove, toUpdate, toCreate); } });
@Override public void run() { List<Region> regions = objectManager.find(Region.class, REGION.REMOVED, new Condition(ConditionType.NULL)); if (regions.size() == 0) { return; } Region localRegion = null; Map<Long, Region> regionMap = new HashMap<Long, Region>(); for(Region region : regions) { regionMap.put(region.getId(), region); if(region.getLocal()) { localRegion = region; } } HashSet<String> existingLinks = new HashSet<String>(); cleanLinks(regionMap, existingLinks, localRegion); cleanAgents(existingLinks); reconcileAccountLinks(); }
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.Region from) { setId(from.getId()); setName(from.getName()); setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setUrl(from.getUrl()); setPublicValue(from.getPublicValue()); setSecretValue(from.getSecretValue()); setLocal(from.getLocal()); }