Package org.rhq.enterprise.server.agentclient

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


            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

                // 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

        } 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

                    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

            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

                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

                bundleManager.addBundleResourceDeploymentHistoryInNewTrans(subjectManager.getOverlord(),
                    resourceDeploy.getId(), history);

                // get a connection to the agent and tell it to purge the bundle from the file system
                Subject overlord = subjectManager.getOverlord();
                AgentClient agentClient = agentManager.getAgentClient(overlord, resourceDeploy.getResource().getId());
                BundleAgentService bundleAgentService = agentClient.getBundleAgentService();
                BundlePurgeRequest request = new BundlePurgeRequest(resourceDeploy);
                BundlePurgeResponse results = bundleAgentService.purge(request);
                if (!results.isSuccess()) {
                    String errorMessage = results.getErrorMessage();
                    failedToPurge.put(resourceDeploy, errorMessage);
View Full Code Here

    private BundleResourceDeployment scheduleBundleResourceDeployment(Subject subject, BundleDeployment deployment,
        Resource bundleTarget, boolean isCleanDeployment, boolean isRevert) throws Exception {

        int bundleTargetResourceId = bundleTarget.getId();
        AgentClient agentClient = agentManager.getAgentClient(subjectManager.getOverlord(), bundleTargetResourceId);
        BundleAgentService bundleAgentService = agentClient.getBundleAgentService();

        // The BundleResourceDeployment record must exist in the db before the agent request because the agent may try
        // to add History to it during immediate deployments. So, create and persist it (requires a new trans).
        BundleResourceDeployment resourceDeployment = bundleManager.createBundleResourceDeploymentInNewTrans(
            subjectManager.getOverlord(), deployment.getId(), bundleTargetResourceId);
View Full Code Here

     */
    public void updateAgentInventoryStatus(List<Resource> platforms, List<Resource> servers) {
        ResourceSyncInfo syncInfo;

        for (Resource platform : platforms) {
            AgentClient agentClient = agentManager.getAgentClient(platform.getAgent());
            if (agentClient != null) {
                try {
                    //syncInfo = entityManager.find(ResourceSyncInfo.class, platform.getId());
                    PlatformSyncInfo platformSyncInfo = getPlatformSyncInfo(platform.getAgent());
                    agentClient.getDiscoveryAgentService().synchronizePlatform(platformSyncInfo);
                } catch (Exception e) {
                    LOG.warn("Could not perform commit synchronization with agent for platform [" + platform.getName()
                        + "]", e);
                }
            } else {
                LOG.warn("Could not perform commit sync with agent for platform [" + platform.getName()
                    + "]; will expect agent to do it later");
            }
        }
        for (Resource server : servers) {
            // Only update servers if they haven't already been updated at the platform level
            if (!platforms.contains(server.getParentResource())) {
                AgentClient agentClient = agentManager.getAgentClient(server.getAgent());
                if (agentClient != null) {
                    try {
                        //syncInfo = entityManager.find(ResourceSyncInfo.class, server.getId());
                        Collection<ResourceSyncInfo> syncInfos = getResourceSyncInfo(server.getId());
                        agentClient.getDiscoveryAgentService().synchronizeServer(server.getId(), syncInfos);
                    } catch (Exception e) {
                        LOG.warn("Could not perform commit synchronization with agent for server [" + server.getName()
                            + "]", e);
                    }
                } else {
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.agentclient.AgentClient

Copyright © 2018 www.massapicom. 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.