Examples of AgentClient


Examples of org.rhq.enterprise.server.agentclient.AgentClient

        RetrievePackageBitsRequest transferRequest = new RetrievePackageBitsRequest(persistedRequest.getId(),
            resourceId, transferPackage);

        // Make call to agent
        try {
            AgentClient agentClient = agentManager.getAgentClient(agent);
            ContentAgentService agentService = agentClient.getContentAgentService();
            agentService.retrievePackageBits(transferRequest);
        } catch (RuntimeException e) {
            LOG.error("Error while sending deploy request to agent", e);

            // Update the request with the failure
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

        Agent agent = resource.getAgent();

        // Make call to agent
        List<DeployPackageStep> packageStepList;
        try {
            AgentClient agentClient = agentManager.getAgentClient(agent);
            ContentAgentService agentService = agentClient.getContentAgentService();
            packageStepList = agentService.translateInstallationSteps(resourceId, packageDetails);
        } catch (PluginContainerException e) {
            LOG.error("Error while sending deploy request to agent", e);

            // Throw so caller knows an error happened
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

                log.warn(msg);
                throw new CancelJobException(msg);
            }

            AgentManagerLocal agentManager = LookupUtil.getAgentManager();
            AgentClient agentClient = agentManager.getAgentClient(getOverlord(), resource.getId());

            agentClient.getOperationAgentService().invokeOperation(resourceHistory.getJobId().toString(),
                resource.getId(), schedule.getOperationName(), schedule.getParameters());
        } catch (Exception e) {
            // failed to even send to the agent, immediately mark the job as failed
            resourceHistory.setErrorMessage(ThrowableUtil.getStackAsString(e));
            operationManager.updateOperationHistory(s, resourceHistory);
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

    public void saveChangeSetContent(Subject subject, int resourceId, String driftDefName, String token,
        File changeSetFilesZip) throws Exception {
        authorizeOrFail(subject, resourceId, "Can not update drifts");
        saveChangeSetFiles(subject, changeSetFilesZip);

        AgentClient agent = agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
        DriftAgentService driftService = agent.getDriftAgentService();
        driftService.ackChangeSetContent(resourceId, driftDefName, token);
    }
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

            Resource resource = entityManager.find(Resource.class, resourceId);
            if (null == resource) {
                throw new IllegalArgumentException("Resource not found [" + resourceId + "]");
            }

            AgentClient agentClient = agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
            DriftAgentService service = agentClient.getDriftAgentService();
            // this is a one-time on-demand call. If it fails throw an exception to make sure the user knows it
            // did not happen. But clean it up a bit if it's a connect exception
            try {
                service.detectDrift(resourceId, driftDef);
            } catch (CannotConnectException e) {
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

                // TODO security check!

                // tell the agent first - we don't want the agent reporting on the drift def after we delete it
                boolean unscheduledOnAgent = false;
                try {
                    AgentClient agentClient = agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
                    DriftAgentService service = agentClient.getDriftAgentService();
                    service.unscheduleDriftDetection(resourceId, doomedDriftDef);
                    unscheduledOnAgent = true;
                } catch (Exception e) {
                    log.warn(" Unable to inform agent of unscheduled drift detection  [" + doomedDriftDef + "]", e);
                }
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

        } catch (Exception e) {
            throw new RuntimeException("Failed to pin snapshot", e);
        }

        try {
            AgentClient agent = agentManager.getAgentClient(subjectManager.getOverlord(), driftDef.getResource()
                .getId());
            DriftAgentService driftService = agent.getDriftAgentService();
            driftService.pinSnapshot(driftDef.getResource().getId(), driftDef.getName(), snapshot);
        } catch (Exception e) {
            log.warn("Unable to notify agent that DriftDefinition[driftDefinitionId: " + driftDefId
                + ", driftDefinitionName: " + driftDef.getName() + "] has been pinned. The agent may be down.", e);
        }
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

                    driftServerPlugin.copyChangeSet(subject, template.getChangeSetId(), driftDef.getId(), resourceId);
                }
            }
            resource.setAgentSynchronizationNeeded();

            AgentClient agentClient = agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
            DriftAgentService service = agentClient.getDriftAgentService();
            try {
                DriftSnapshot snapshot = null;
                if (driftDef.getTemplate() != null && driftDef.getTemplate().isPinned()) {
                    snapshot = getSnapshot(subject, new DriftSnapshotRequest(driftDef.getId()));
                }
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

            entityManager.detach(resource);
            if (null != doomedAgent) {
                entityManager.detach(doomedAgent);
            }

            AgentClient agentClient = null;
            try {
                // The test code does not always generate agents for the resources. Catch and log any problem but continue
                agentClient = agentManager.getAgentClient(overlord, resourceId);
            } catch (Throwable t) {
                LOG.warn("No AgentClient found for resource [" + resource
                    + "]. Unable to inform agent of inventory removal (this may be ok): " + t);
            }

            // since we delete the resource asynchronously, make sure we remove things that would cause system
            // side effects after markForDeletion completed but before the resource is actually removed from the DB

            // delete the resource and all its children
            if (isDebugEnabled) {
                LOG.debug("Marking resource [" + resource + "] for asynchronous uninventory");
            }

            // set agent references null
            // foobar the resourceKeys
            // update the inventory status to UNINVENTORY
            List<Integer> toBeDeletedResourceIds = getDescendents(resourceId);

            int i = 0;
            if (isDebugEnabled) {
                LOG.debug("== total size : " + toBeDeletedResourceIds.size());
            }

            while (i < toBeDeletedResourceIds.size()) {
                int j = i + 1000;
                if (j > toBeDeletedResourceIds.size())
                    j = toBeDeletedResourceIds.size();
                List<Integer> idsToDelete = toBeDeletedResourceIds.subList(i, j);
                if (isDebugEnabled) {
                    LOG.debug("== Bounds " + i + ", " + j);
                }

                // refresh overlord session for each batch to avoid session timeout
                overlord = subjectManager.getOverlord();
                boolean hasErrors = uninventoryResourcesBulkDelete(overlord, idsToDelete);
                if (hasErrors) {
                    throw new IllegalArgumentException("Could not remove resources from their containing groups");
                }
                i = j;
            }

            // QUERY_MARK_RESOURCES_FOR_ASYNC_DELETION is an expensive recursive query
            // But luckily we have already (through such a recursive query above) determined the doomed resources
            //        Query markDeletedQuery = entityManager.createNamedQuery(Resource.QUERY_MARK_RESOURCES_FOR_ASYNC_DELETION);
            //        markDeletedQuery.setParameter("resourceId", resourceId);
            //        markDeletedQuery.setParameter("status", InventoryStatus.UNINVENTORIED);
            //        int resourcesDeleted = markDeletedQuery.executeUpdate();

            i = 0;
            int resourcesDeleted = 0;
            while (i < toBeDeletedResourceIds.size()) {
                int j = i + 1000;
                if (j > toBeDeletedResourceIds.size())
                    j = toBeDeletedResourceIds.size();
                List<Integer> idsToDelete = toBeDeletedResourceIds.subList(i, j);

                Query markDeletedQuery = entityManager
                    .createNamedQuery(Resource.QUERY_MARK_RESOURCES_FOR_ASYNC_DELETION_QUICK);
                markDeletedQuery.setParameter("resourceIds", idsToDelete);
                markDeletedQuery.setParameter("status", InventoryStatus.UNINVENTORIED);
                resourcesDeleted += markDeletedQuery.executeUpdate();
                i = j;
            }

            if (resourcesDeleted != toBeDeletedResourceIds.size()) {
                LOG.error("Tried to uninventory " + toBeDeletedResourceIds.size()
                    + " resources, but actually uninventoried " + resourcesDeleted);
            }

            // flush to make sure the db is successfully updated with changes before we make more slsb calls and
            // before we notify the agent
            entityManager.flush();

            // still need to tell the agent about the removed resources so it stops avail reports
            // but not if this is a synthetic agent that was created in the REST-api
            // See org.rhq.enterprise.server.rest.ResourceHandlerBean.createPlatformInternal()
            // See also https://docs.jboss.org/author/display/RHQ/Virtual+platforms+and+synthetic+agents
            if (agentClient != null) {
                if (agentClient.getAgent() == null || agentClient.getAgent().getName() == null
                    || !agentClient.getAgent().getName().startsWith(ResourceHandlerBean.DUMMY_AGENT_NAME_PREFIX)) { // don't do that on "REST-agents"
                    try {
                        if (agentClient.pingService(3000L)) {
                            agentClient.getDiscoveryAgentService().uninventoryResource(resourceId);
                        } else {
                            LOG.warn(" Unable to inform agent [" + agentClient.getAgent().getName()
                                + "] of inventory removal for resource [" + resourceId
                                + "]. Agent can not be reached or is not accepting service requests.");
                        }
                    } catch (Exception e) {
                        LOG.warn(" Unable to inform agent of inventory removal for resource [" + resourceId + "]", e);
View Full Code Here

Examples of org.rhq.enterprise.server.agentclient.AgentClient

                new IllegalStateException("No agent is associated with the resource with id [" + resourceId + "]");
            } else if (agent.getName().startsWith(ResourceHandlerBean.DUMMY_AGENT_NAME_PREFIX)
                && agent.getAgentToken().startsWith(ResourceHandlerBean.DUMMY_AGENT_TOKEN_PREFIX)) {
                return getResourceById(subject, resourceId).getCurrentAvailability();
            }
            AgentClient client = agentManager.getAgentClient(agent);
            if (client == null) {
                throw new IllegalStateException("No agent is associated with the resource with id [" + resourceId + "]");
            }

            AvailabilityReport report = null;

            // first, quickly see if we can even ping the agent, if not, don't bother trying to get the resource avail
            boolean agentPing = client.pingService(5000L);
            if (agentPing) {
                // we can't serialize the resource due to the hibernate proxies (agent can't deserialize hibernate objs)
                // but we know we only need the basics for the agent to collect availability, so create a bare resource object
                Resource bareResource = new Resource(res.getResourceKey(), res.getName(), res.getResourceType());
                bareResource.setId(res.getId());
                bareResource.setUuid(res.getUuid());
                // root the avail check at the desired resource. Ask for a full report to guarantee that we
                // get back the agent-side avail for the resource and keep the server in sync.  This also means we'll
                // get the descendants as well.
                report = client.getDiscoveryAgentService().getCurrentAvailability(bareResource, false);
            }

            if (report != null) {
                // although the data came from the agent this should be processed like a server-side report
                // because it was requested and initiated by the server (bz 1094540).  The availabilities will
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.