public ProjectLock(Account project) { super("PROJECT.LOCK." + project.getId()); } }
@Override public Set<Identity> getIdentities(Account account) { Set<Identity> identities = new HashSet<>(); identities.add(new Identity(ProjectConstants.RANCHER_ID, String.valueOf(account.getId()))); return identities; }
protected <T> List<T> list(Account account, Class<T> type) { return objectManager.find(type, ObjectMetaDataManager.REMOVED_FIELD, null, ObjectMetaDataManager.ACCOUNT_FIELD, account.getId()); }
protected Network findIpSecNetwork(Account account) { return objectManager.findAny(Network.class, ObjectMetaDataManager.ACCOUNT_FIELD, account.getId(), ObjectMetaDataManager.KIND_FIELD, NetworkConstants.KIND_CNI, ObjectMetaDataManager.REMOVED_FIELD, null); }
protected Network createNetwork(String kind, Account account, Map<String, Network> networksByKind, String name, String key, Object... valueKeyValue) { Network network = networksByKind.get(kind); if (network != null) { return network; } Map<String, Object> data = key == null ? new HashMap<String, Object>() : CollectionUtils.asMap(key, valueKeyValue); data.put(ObjectMetaDataManager.NAME_FIELD, name); data.put(ObjectMetaDataManager.ACCOUNT_FIELD, account.getId()); data.put(ObjectMetaDataManager.KIND_FIELD, kind); return resourceDao.createAndSchedule(Network.class, data); }
protected Map<String, Network> getNetworksByUuid(Account account) { Map<String, Network> result = new HashMap<>(); for (Network network : objectManager.find(Network.class, NETWORK.ACCOUNT_ID, account.getId(), NETWORK.REMOVED, null)) { result.put(network.getKind(), network); } return result; } }
@Override public String getOption() { String agentId = options.getOption(Policy.AGENT_ID); if (agentId == null) { log.error("Failed to determine the proper agent ID for subscription for account [{}]", account.getId()); throw new ClientVisibleException(ResponseCodes.FORBIDDEN); } return agentId; } });
@Override public ProjectMember createProjectMember(Account project, Member member) { Map<Object, Object> properties = new HashMap<>(); properties.put(PROJECT_MEMBER.PROJECT_ID, project.getId()); properties.put(PROJECT_MEMBER.ACCOUNT_ID, project.getId()); properties.put(PROJECT_MEMBER.NAME, member.getName()); properties.put(PROJECT_MEMBER.EXTERNAL_ID, member.getExternalId()); properties.put(PROJECT_MEMBER.EXTERNAL_ID_TYPE, member.getExternalIdType()); properties.put(PROJECT_MEMBER.ROLE, member.getRole()); return resourceDao.create(ProjectMember.class, objectManager.convertToPropertiesFor(ProjectMember.class, properties)); }
protected String calculateEnvironmentHealthState(final Account env) { List<Stack> stacks = objectManager.find(Stack.class, STACK.ACCOUNT_ID, env.getId(), STACK.REMOVED, null); List<HealthChecker> hcs = new ArrayList<>(); for (Stack stack : stacks) { hcs.add(new StackHealthCheck(stack)); } return calculateHealthState(hcs); }
protected <T> List<T> hostList(Account account, Class<T> type) { return objectManager.find(type, ObjectMetaDataManager.STATE_FIELD, new Condition(ConditionType.NE, CommonStatesConstants.PURGED), ObjectMetaDataManager.ACCOUNT_FIELD, account.getId()); }
private void reconcileAccountLinks() { List<Region> regions = objectManager.find(Region.class, REGION.REMOVED, new Condition(ConditionType.NULL)); if (regions.size() == 0) { return; } List<Account> accounts = objectManager.find(Account.class, ACCOUNT.KIND, AccountConstants.PROJECT_KIND, ACCOUNT.REMOVED, new Condition(ConditionType.NULL)); for(Account account : accounts) { try { regionService.reconcileExternalLinks(account.getId()); } catch (Exception ex) { log.warn(String.format("Failed to reconcile external link for %s - %s", account.getId(), ex)); } } }
public void run() { logger.info("ipsec.service.enable.healthcheck changed"); List<Account> accounts = objectManager.find(Account.class, ACCOUNT.KIND, AccountConstants.PROJECT_KIND, ACCOUNT.REMOVED, new Condition(ConditionType.NULL)); for(Account account : accounts) { agentMetadata.updateMetadata(account.getId()); } } };
protected void deleteOldAccountLinks(Account account, List<? extends Long> newAccountIds) { List<? extends AccountLink> allLinks = objectManager.find(AccountLink.class, ACCOUNT_LINK.ACCOUNT_ID, account.getId(), ACCOUNT_LINK.REMOVED, null); for (AccountLink link : allLinks) { if (!newAccountIds.contains(link.getLinkedAccountId())) { objectProcessManager.scheduleStandardProcessAsync(StandardProcess.REMOVE, link, null); } } }
@Override public void run() { systemStackTrigger.trigger(env.getId()); objectManager.setFields(env, ACCOUNT.PROJECT_TEMPLATE_ID, template.getId()); } });
@SuppressWarnings("unchecked") @Override public Object perform(String name, Object obj, ApiRequest request) { Account project = (Account) obj; project = authDao.getAccountById(project.getId()); if (project == null) { throw new ClientVisibleException(ResponseCodes.NOT_FOUND); } LinkedHashMap<String, Object> reqObj = (LinkedHashMap<String, Object>) request.getRequestObject(); List<Map<String, String>> members = (List<Map<String, String>>) reqObj.get("members"); return projectMemberResourceManager.setMembers(project, members, false); }
@Override public SchemaFactory getSchemaFactory(Account account, Policy policy, ApiRequest request) { SchemaFactory factory = authorizationProvider.getSchemaFactory(account, policy, request); if (factory == null) { return null; } return new DynamicSchemaFactory(account.getId(), factory, dynamicSchemaDao, jsonMapper, getRole(account, policy, request), schemaCache); }
private Condition getMultiAccountInstanceSearchCondition(final MetaHelperInfo helperInfo) { Condition condition = INSTANCE.ACCOUNT_ID.eq(helperInfo.getAccount().getId()); if (!helperInfo.getOtherAccountsServicesIds().isEmpty()) { condition = INSTANCE.ACCOUNT_ID.eq(helperInfo.getAccount().getId()).or( SERVICE_EXPOSE_MAP.SERVICE_ID.in(helperInfo.getOtherAccountsServicesIds())); } return condition; }
protected Long getAccountId(AgentInstanceBuilderImpl builder) { if (builder.isAccountOwned() && builder.getAccountId() != null) { return builder.getAccountId(); } return accountDao.getSystemAccount().getId(); }
@Override protected Object updateInternal(String type, String id, Object obj, ApiRequest apiRequest) { Policy policy = (Policy) ApiContext.getContext().getPolicy(); Account project = (Account) obj; if (authDao.isProjectOwner(project.getId(), policy.getAccountId(), policy.isOption(Policy.AUTHORIZED_FOR_ALL_ACCOUNTS), policy.getIdentities())) { return super.updateInternal(type, id, obj, apiRequest); } else { throw new ClientVisibleException(ResponseCodes.FORBIDDEN, "Forbidden", "You must be a project owner to update the name or description.", null); } }