io.cattle.platform.core.model.Agent.getAccountId()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中io.cattle.platform.core.model.Agent.getAccountId()方法的一些代码示例,展示了Agent.getAccountId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Agent.getAccountId()方法的具体详情如下:
包路径:io.cattle.platform.core.model.Agent
类名称:Agent
方法名:getAccountId

Agent.getAccountId介绍

[英]Getter for cattle.agent.account_id.
[中]cattle.agent.account_id的Getter。

代码示例

代码示例来源:origin: rancher/cattle

protected Map<String, Object> createData(Agent agent, String uuid, Map<String, Object> data) {
  Map<String, Object> properties = new HashMap<>(data);
  properties.put(HostConstants.FIELD_REPORTED_UUID, uuid);
  properties.remove(ObjectMetaDataManager.UUID_FIELD);
  Long accountId = DataAccessor.fromDataFieldOf(agent).withKey(AgentConstants.DATA_AGENT_RESOURCES_ACCOUNT_ID).as(Long.class);
  if (accountId == null) {
    accountId = agent.getAccountId();
  }
  properties.put(ObjectMetaDataManager.ACCOUNT_FIELD, accountId);
  properties.put(AgentConstants.ID_REF, agent.getId());
  return properties;
}

代码示例来源:origin: rancher/cattle

public static Map<String, Object> getAgentAuth(Agent agent, ObjectManager objectManager) {
  Account account = objectManager.loadResource(Account.class, agent.getAccountId());
  if (account == null) {
    return null;
  }
  return AgentUtils.getAgentAuth(account, objectManager, null);
}

代码示例来源:origin: rancher/cattle

protected Credential getCredential(Agent agent) {
  Account account = loadResource(Account.class, agent.getAccountId());
  for (Credential cred : children(account, Credential.class)) {
    if (cred.getKind().equals(CredentialConstants.KIND_AGENT_API_KEY) && CommonStatesConstants.ACTIVE.equals(cred.getState())) {
      return cred;
    }
  }
  return null;
}

代码示例来源:origin: rancher/cattle

protected AgentAndHost loadAgentAndHostData(ImmutablePair<Long, String> agentIdAndHostUuid) {
  Long agentId = agentIdAndHostUuid.left;
  String hostUuid = agentIdAndHostUuid.right;
  Agent agent = objectManager.loadResource(Agent.class, agentId);
  Host host = null;
  Map<String, Host> hosts = null;
  if (agent != null) {
    hosts = agentDao.getHosts(agent.getId());
    host = hosts.get(hostUuid);
  }
  if (agent == null || agent.getAccountId() == null || host == null)
    throw new CantFindAgentAndHostException();
  return new AgentAndHost(agent.getAccountId(), host.getId());
}

代码示例来源:origin: rancher/cattle

@Override
public boolean areAllCredentialsActive(Agent agent) {
  List<Long> authedRoleAccountIds = DataAccessor.fieldLongList(agent, AgentConstants.FIELD_AUTHORIZED_ROLE_ACCOUNTS);
  if (agent.getAccountId() == null) {
    return false;
  }
  Set<Long> accountIds = new HashSet<>();
  accountIds.add(agent.getAccountId());
  for (Long aId : authedRoleAccountIds) {
    accountIds.add(aId);
  }
  List<? extends Credential> creds = create()
      .selectFrom(CREDENTIAL)
      .where(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE)
          .and(CREDENTIAL.ACCOUNT_ID.in(accountIds)))
      .fetch();
  Set<Long> credAccountIds = new HashSet<>();
  for (Credential cred : creds) {
    credAccountIds.add(cred.getAccountId());
  }
  return accountIds.equals(credAccountIds);
}

代码示例来源:origin: rancher/cattle

protected Account createPrimaryAccount(Agent agent, String role) {
  if (agent.getAccountId() != null) {
    return getObjectManager().loadResource(Account.class, agent.getAccountId());
  }
  String uuid = getAccountUuid(agent);
  Account account = accountDao.findByUuid(uuid);
  if (account == null) {
    Object data = createAccountDataWithActAsValue(role);
    account = getObjectManager().create(Account.class,
        ACCOUNT.UUID, uuid,
        ACCOUNT.DATA, data,
        ACCOUNT.KIND, "agent");
  }
  return account;
}

代码示例来源:origin: rancher/cattle

protected void deleteAgentAccount(Long agentId, Map<String, Object> data) {
  if (agentId == null) {
    return;
  }
  Agent agent = getObjectManager().loadResource(Agent.class, agentId);
  Account account  = getObjectManager().loadResource(Account.class, agent.getAccountId());
  if (account == null) {
    return;
  }
  deactivateThenScheduleRemove(account, data);
}

代码示例来源:origin: rancher/cattle

@Override
public Object create(String type, ApiRequest request, ResourceManager next) {
  String ip = request.getClientIp();
  Agent agent = request.proxyRequestObject(Agent.class);
  /*
   * This ensures that the accountId is always set from the request and
   * never overwritten by the default accountId setting logic. In the
   * situation in which the client doesn't have access to the accountId
   * field, the result will be null, which is correct. You want it to be
   * null so that the AgentCreate logic will create an account for this
   * Agent
   */
  agent.setAccountId(agent.getAccountId());
  String uri = agent.getUri();
  String user = DataUtils.getFieldFromRequest(request, AgentConstants.USER, String.class);
  if (uri == null) {
    uri = getUri(user, ip);
    if (uri != null) {
      isUnique(uri);
      agent.setUri(uri);
    }
  }
  return super.create(type, request, next);
}

代码示例来源:origin: rancher/cattle

Account account = objectManager.loadResource(Account.class, agent.getAccountId());
if (account != null && account.getRemoved() == null) {
  deactivateThenScheduleRemove(account, state.getData());

代码示例来源:origin: rancher/cattle

@Override
public HandlerResult handle(ProcessState state, ProcessInstance process) {
  Agent agent = (Agent) state.getResource();
  Long accountId = agent.getAccountId();
  if (accountId != null || !CREATE_ACCOUNT.get()) {
    return new HandlerResult(AGENT.ACCOUNT_ID, accountId);
  }
  DataAccessor.fromMap(state.getData()).withScope(AccountConstants.class).withKey(AccountConstants.OPTION_CREATE_APIKEY).set(true);
  DataAccessor.fromMap(state.getData()).withScope(AccountConstants.class).withKey(AccountConstants.OPTION_CREATE_APIKEY_KIND).set(
      CredentialConstants.KIND_AGENT_API_KEY);
  DataAccessor.fromMap(state.getData()).withScope(CredentialConstants.class).withKey(CredentialConstants.PUBLIC_VALUE)
      .set(state.getData().get(CredentialConstants.PUBLIC_VALUE));
  DataAccessor.fromMap(state.getData()).withScope(CredentialConstants.class).withKey(CredentialConstants.SECRET_VALUE)
      .set(state.getData().get(CredentialConstants.SECRET_VALUE));
  List<? extends String> roles =
      DataAccessor.fromDataFieldOf(agent).withKey(AgentConstants.DATA_REQUESTED_ROLES).withDefault(Collections.EMPTY_LIST)
          .asList(jsonMapper, String.class);
  sortRoles(roles);
  String primaryRole = getPrimaryRole(roles); // note null is an acceptable value 
  Account account = createPrimaryAccount(agent, primaryRole);
  create(account, state.getData());
  Map<String, Object> data = new HashMap<>();
  data.put(AgentConstants.FIELD_ACCOUNT_ID, account.getId());
  List<? extends String> secondaryRoles = getSecondaryRoles(roles);
  List<Long> authedRoleAccounts = createSecondaryAccounts(agent, secondaryRoles, state);
  if (!authedRoleAccounts.isEmpty()) {
    data.put(AgentConstants.FIELD_AUTHORIZED_ROLE_ACCOUNTS, authedRoleAccounts);
  }
  return new HandlerResult(data);
}

代码示例来源:origin: rancher/cattle

} else {
  Account account = objectManager.loadResource(Account.class, agent.getAccountId());
  Map<String, Object> auth = AgentUtils.getAccountScopedAuth(account, objectManager, account.getKind());
  setAuthEnvVars(data, auth);

代码示例来源:origin: rancher/cattle

/**
 * {@inheritDoc}
 */
@Override
public void from(io.cattle.platform.core.model.Agent 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());
  setUri(from.getUri());
  setManagedConfig(from.getManagedConfig());
  setZoneId(from.getZoneId());
  setExternalId(from.getExternalId());
}

相关文章