private void cleanupExternalLinks(Region region) { for (AccountLink link : objectManager.find(AccountLink.class, ACCOUNT_LINK.REMOVED, null, ACCOUNT_LINK.LINKED_REGION_ID, region.getId())) { if (!link.getState().equalsIgnoreCase(CommonStatesConstants.REMOVING)) { objectProcessManager.executeStandardProcess(StandardProcess.REMOVE, link, null); } } } }
@Override public boolean isRegionsEmpty(Agent agent, Account account, Map<String, Long> externalLinks, Map<String, ExternalProject> projects, Map<Long, Region> regionsIds, Map<String, Region> regionNameToRegion) { List<Region> regions = objectManager.find(Region.class, REGION.REMOVED, (Object) null); for(Region region : regions) { regionsIds.put(region.getId(), region); regionNameToRegion.put(region.getName(), region); } getLinkedEnvironments(account.getId(), externalLinks, regionsIds, projects); boolean noExternalLinks = externalLinks.isEmpty(); List<? extends ExternalCredential> existing = DataAccessor.fieldObjectList(agent, AccountConstants.FIELD_EXTERNAL_CREDENTIALS, ExternalCredential.class, jsonMapper); boolean noExternalCreds = existing.isEmpty(); if (noExternalLinks && noExternalCreds) { return true; } return false; }
@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(); }
ACCOUNT_LINK.LINKED_REGION_ID, region.getId(), "linkedAccountUuid", externalProject.getUuid()); toUpdate.add(link); } catch(Exception ex) {
private void getLinkedEnvironments(long accountId, Map<String, Long> links, Map<Long, Region> regionsIds, Map<String, ExternalProject> externalProjects) { List<AccountLink> accountLinks = objectManager.find(AccountLink.class, ACCOUNT_LINK.ACCOUNT_ID, accountId, ACCOUNT_LINK.REMOVED, null, ACCOUNT_LINK.LINKED_REGION_ID, new Condition(ConditionType.NOTNULL)); for (AccountLink link : accountLinks) { if (link.getState().equalsIgnoreCase(CommonStatesConstants.REMOVING)) { continue; } if(link.getState().equalsIgnoreCase(CommonStatesConstants.REMOVED)) { continue; } Region targetRegion = regionsIds.get(link.getLinkedRegionId()); if (targetRegion == null) { continue; } String UUID = getUUID(targetRegion.getName(), link.getLinkedAccount()); if (!externalProjects.containsKey(UUID)) { links.put(UUID, targetRegion.getId()); } } }
/** * {@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()); }