io.cattle.platform.core.model.Agent类的使用及代码示例

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

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

Agent介绍

[英]This class is generated by jOOQ.
[中]这个类是由jOOQ生成的。

代码示例

代码示例来源: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());
}

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

protected EventService buildDelegate(long agentId) {
  Map<String, Object> instanceData = new LinkedHashMap<>();
  Agent hostAgent = getAgentForDelegate(agentId, instanceData);
  if (hostAgent == null) {
    return null;
  }
  String hostAgentUri = hostAgent.getUri();
  if (hostAgentUri != null && !hostAgentUri.startsWith(EVENTING)) {
    return null;
  }
  return new WrappedEventService(hostAgent.getId(), true, eventService, instanceData, jsonMapper, delegateDao);
}

代码示例来源: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

protected String getAccountUuid(Agent agent, String role) {
  return "agentAccount" + agent.getId() + "-" + role;
}

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

protected void pingFailure(Agent agent) {
  long count = status.getUnchecked(agent.getId()).failed();
  if (count < 3) {
    log.info("Missed ping from agent [{}] count [{}]", agent.getId(), count);
  } else {
    log.error("Failed to get ping from agent [{}] count [{}]", agent.getId(), count);
  }
  if (count >= BAD_PINGS.get()) {
    try {
      agent = objectManager.reload(agent);
      if (CommonStatesConstants.ACTIVE.equals(agent.getState())) {
        Host host = objectManager.findAny(Host.class, HOST.AGENT_ID, agent.getId());
        if (host != null) {
          log.error("Scheduling reconnect for agent [{}] host [{}] count [{}]", agent.getId(), host.getId(), count);
        } else {
          log.error("Scheduling reconnect for agent [{}] count [{}]", agent.getId(), count);
        }
        processManager.scheduleProcessInstance(AgentConstants.PROCESS_RECONNECT, agent, null);
      }
    } catch (ProcessInstanceException e) {
      if (e.getExitReason() != ExitReason.CANCELED) {
        throw e;
      }
    }
  }
}

代码示例来源: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

@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

private Map<String, Object> getInstanceProperties(Agent agent, AgentInstanceBuilderImpl builder) {
  Map<Object, Object> properties = new HashMap<Object, Object>();
  properties.put(INSTANCE.ACCOUNT_ID, getAccountId(builder));
  properties.put(INSTANCE.AGENT_ID, agent.getId());
  properties.put(InstanceConstants.FIELD_IMAGE_UUID, builder.getImageUuid());
  properties.put(INSTANCE.NAME, builder.getName());
  properties.put(INSTANCE.ZONE_ID, agent.getZoneId());
  properties.put(INSTANCE.KIND, builder.getInstanceKind());
  properties.put(InstanceConstants.FIELD_PRIVILEGED, builder.isPrivileged());
  properties.put(InstanceConstants.FIELD_NETWORK_IDS, getNetworkIds(agent, builder));
  properties.putAll(builder.getParams());
  addAdditionalProperties(properties, agent, builder);
  return objectManager.convertToPropertiesFor(Instance.class, properties);
}

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

private boolean isAgentDisconnected(Host host) {
  if (host == null) {
    return false;
  }
  Agent agent = context.objectManager.loadResource(Agent.class, host.getAgentId());
  if (agent != null && (AgentConstants.STATE_RECONNECTING.equals(agent.getState()) ||
      AgentConstants.STATE_DISCONNECTED.equals(agent.getState()) || AgentConstants.STATE_DISCONNECTING
        .equals(agent.getState()))) {
    return true;
  }
  return false;
}

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

protected EventService getWrappedEventService(long agentId) {
  Agent agent = objectManager.loadResource(Agent.class, agentId);
  if (agent == null) {
    return null;
  }
  String uri = agent.getUri();
  if (uri != null && !uri.startsWith(EVENTING)) {
    return null;
  }
  return new WrappedEventService(agentId, false, eventService, null, jsonMapper, delegateDao);
}

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

@Override
  public ExternalAgent handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
    int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode >= 300) {
      throw new IOException(String.format("Failed to delete external agent externalId=%s, response error code %s", agent.getUuid(),
          response.getStatusLine().getReasonPhrase()));
    }
    return null;
  }
});

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

@Override
public HandlerResult handle(ProcessState state, ProcessInstance process) {
  Agent agent = (Agent) state.getResource();
  if (agent.getExternalId() != null) {
    return null;
  }
  regionService.deactivateAndRemoveExternalAgent(agent);
  return null;
}

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

@Override
  public HandlerResult handle(ProcessState state, ProcessInstance process) {
    Object resource = state.getResource();

    Long agentId = AgentLocatorImpl.getAgentId(resource);
    Agent agent = objectManager.loadResource(Agent.class, agentId);

    if (agent == null || agent.getRemoved() != null) {
      return null;
    }

    try {
      objectProcessManager.scheduleStandardProcess(StandardProcess.DEACTIVATE,
          agent, ProcessUtils.chainInData(state.getData(), AgentConstants.PROCESS_DEACTIVATE,
              AgentConstants.PROCESS_REMOVE));
    } catch (ProcessCancelException e) {
      objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, agent, state.getData());
    }

    return null;
  }
}

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

public AgentResourceCreateLock(Agent agent) {
  super("AGENT.RESOUCE.CREATE." + agent.getId());
}

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

private void cleanAgents(HashSet<String> existingLinks) {
  List<Agent> agents = objectManager.find(Agent.class, AGENT.REMOVED, new Condition(ConditionType.NULL),
      AGENT.EXTERNAL_ID, new Condition(ConditionType.NOTNULL));
  
  if(agents.size() > 0) { 
    for(Agent agent : agents) {
      try {
        String[] uri = agent.getUri().substring(RegionUtil.EXTERNAL_AGENT_URI_PREFIX.length()).split("_");
        String regionEnv = String.format("%s:%s", uri[0], uri[1]);
        if (existingLinks.contains(regionEnv)) {
          continue;
        }
        cleanupAgent(agent);
      } catch (Exception ex) {
        log.warn(String.format("Fail to remove agent ", agent.getId(), ex));
      }
    }
  }
}

代码示例来源: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

protected Long getAgent() {
  ApiRequest request = ApiContext.getContext().getApiRequest();
  Long agentId = getRawAgentId();
  if (agentId != null) {
    return agentId;
  }
  String type = request.getSchemaFactory().getSchemaName(Agent.class);
  ResourceManager rm = getLocator().getResourceManagerByType(type);
  Long id = null;
  /*  This really isn't the best logic.  Basically we are looking for agents with state in STATES */
  for (Object obj : rm.list(type, null, Pagination.limit(2))) {
    if (!(obj instanceof Agent)) {
      continue;
    }
    Agent agent = (Agent)obj;
    if (STATES.contains(agent.getState())) {
      if (id != null) {
        throw new ValidationErrorException(ValidationErrorCodes.MISSING_REQUIRED, "agentId");
      } else {
        if (DISCONNECTED.contains(agent.getState())) {
          processManager.scheduleProcessInstance(AgentConstants.PROCESS_RECONNECT, agent, null);
        }
        id = agent.getId();
      }
    }
  }
  return id;
}

代码示例来源: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

@Override
protected Event callSync(RemoteAgent remoteAgent, Event event, EventCallOptions options) {
  Agent agent = loadResource(Agent.class, remoteAgent.getAgentId());
  if (agent != null && (AgentConstants.STATE_RECONNECTING.equals(agent.getState()) ||
      AgentConstants.STATE_DISCONNECTED.equals(agent.getState()))) {
    return null;
  }
  return super.callSync(remoteAgent, event, options);
}

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

protected Instance createInstance(final Agent agent, final Map<String, Object> properties, final AgentInstanceBuilderImpl builder) {
  return lockManager.lock(new AgentInstanceAgentCreateLock(agent.getUri()), new LockCallback<Instance>() {
    @Override
    public Instance doWithLock() {
      Instance instance = factoryDao.getInstanceByAgent(agent.getId());
      if (instance == null) {
        instance = DeferredUtils.nest(new Callable<Instance>() {
          @Override
          public Instance call() throws Exception {
            return resourceDao.createAndSchedule(Instance.class, properties);
          }
        });
      }
      return instance;
    }
  });
}

相关文章