@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; } });
protected void addInstances(AgentConnectionSimulator simulator, Ping pong, Agent agent) { List<Map<String, Object>> resources = pong.getData().getResources(); for (Map.Entry<String, Object[]> kv : simulator.getInstances().entrySet()) { // This matches the data structure returned by the ping logic in the real ping agent. Map<String, Object> instanceMap = CollectionUtils.asMap( ObjectMetaDataManager.TYPE_FIELD, InstanceConstants.TYPE, ObjectMetaDataManager.UUID_FIELD, kv.getKey(), ObjectMetaDataManager.STATE_FIELD, kv.getValue()[0], "systemContainer", null, "dockerId", kv.getValue()[1], "image", kv.getValue()[2], "labels", new String[0], "created", kv.getValue()[3]); resources.add(instanceMap); } String hostUuid = agent.getUuid() + "-" + 0; Map<String, Object> hostUuidResource = new HashMap<String, Object>(); hostUuidResource.put(ObjectMetaDataManager.TYPE_FIELD, "hostUuid"); hostUuidResource.put(ObjectMetaDataManager.UUID_FIELD, hostUuid); resources.add(hostUuidResource); pong.setOption(Ping.INSTANCES, true); }
protected boolean deactivateAndRemoveExternalAgent(Agent agent, ExternalCredential cred) { Region targetRegion = objectManager.loadResource(Region.class, cred.getRegionId()); if (targetRegion == null) { log.info(String.format("Failed to find target region by name [%s]", cred.getRegionName())); return true; } String regionName = cred.getRegionName(); String envName = cred.getEnvironmentName(); try { log.info(String.format("Removing agent with externalId [%s] in environment [%s] and region [%s]", agent.getUuid(), regionName, envName)); ExternalAgent externalAgent = RegionUtil.getExternalAgent(targetRegion, cred.getAgentUuid(), jsonMapper); if (externalAgent == null) { log.info(String.format("Failed to find agent by externalId [%s] in environment [%s] and region [%s]", agent.getUuid(), regionName, envName)); return true; } RegionUtil.deleteExternalAgent(agent, targetRegion, externalAgent); return true; } catch (Exception e) { log.error( String.format("Failed to deactivate agent with externalId [%s] in environment [%s] and region [%s]", agent.getUuid(), regionName, envName), e); return false; } }
String targetAgentUri = RegionUtil.getTargetAgentUri(localRegion.getName(), account.getName(), agent.getUuid(), targetResourceAccount.getUuid()); log.info(String.format("Creating external agent with uri [%s] in environment [%s] in region [%s]", targetAgentUri, data.put(CredentialConstants.SECRET_VALUE, cred.getSecretValue()); data.put(AgentConstants.FIELD_URI, targetAgentUri); data.put(AgentConstants.FIELD_EXTERNAL_ID, agent.getUuid()); Map<String, String> labels = new HashMap<>(); labels.put(SystemLabels.LABEL_AGENT_SERVICE_METADATA, "true");
/** * {@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()); }