Package org.rhq.core.clientapi.server.drift

Examples of org.rhq.core.clientapi.server.drift.DriftServerService


            ResourceFactoryServerService resourceFactoryServerSerfice = factory
                .getRemotePojo(ResourceFactoryServerService.class);
            ContentServerService contentServerService = factory.getRemotePojo(ContentServerService.class);
            EventServerService eventServerService = factory.getRemotePojo(EventServerService.class);
            BundleServerService bundleServerService = factory.getRemotePojo(BundleServerService.class);
            DriftServerService driftServerService = factory.getRemotePojo(DriftServerService.class);

            ServerServices serverServices = new ServerServices();
            serverServices.setCoreServerService(coreServerService);
            serverServices.setDiscoveryServerService(discoveryServerService);
            serverServices.setMeasurementServerService(measurementServerService);
View Full Code Here


    private void syncWithServer(Resource resource, DriftDefinition driftDefinition) throws IOException {
        Headers headers = createHeaders(resource.getId(), driftDefinition);
        if (!changeSetMgr.changeSetExists(resource.getId(), headers)) {
            log.info("No snapshot found for " + toString(resource.getId(), driftDefinition)
                + ". Downloading snapshot from server");
            DriftServerService driftServer = pluginContainerConfiguration.getServerServices().getDriftServerService();

            DriftSnapshot snapshot = driftServer.getCurrentSnapshot(driftDefinition.getId());

            if (snapshot.getVersion() == -1) {
                // A version of -1 indicates that no change sets have been reported
                // for this definition. This can occur when a user creates a
                // drift definition while the agent is offline for example. At
                // this point we just return and allow the agent to generate the
                // initial snapshot file.
                if (log.isDebugEnabled()) {
                    log.debug("The server does not have any change sets for "
                        + toString(resource.getId(), driftDefinition) + ". An initial snapshot needs to be generated.");
                }
                return;
            }

            headers.setVersion(snapshot.getVersion());

            log.info("Preparing to write snapshot at version " + snapshot.getVersion() + " to disk for "
                + toString(resource.getId(), driftDefinition));
            File currentSnapshotFile = changeSetMgr
                .findChangeSet(resource.getId(), driftDefinition.getName(), COVERAGE);
            writeSnapshotToFile(snapshot, currentSnapshotFile, headers);

            if (driftDefinition.isPinned()) {
                log.debug(driftDefinition + " is pinned. Fetching pinned snapshot...");
                // The pinned snapshot is always the initial change set and only the initial
                // change set.
                DriftSnapshot pinnedSnapshot = driftServer.getSnapshot(driftDefinition.getId(), 0, 0);
                Headers pinnedHeaders = createHeaders(resource.getId(), driftDefinition);
                File pinnedSnapshotFile = new File(currentSnapshotFile.getParent(), DriftDetector.FILE_SNAPSHOT_PINNED);
                log.info("Preparing to write pinned snapshot to disk for "
                    + toString(resource.getId(), driftDefinition));
                writeSnapshotToFile(pinnedSnapshot, pinnedSnapshotFile, pinnedHeaders);

                if (snapshot.getVersion() > 0) {
                    // Drift was previously reported. We will fetch a snapshot of the
                    // latest change set and write that to disk so that we avoid reporting
                    // drift that has already been reported to the server.
                    DriftSnapshot deltaSnapshot = driftServer.getSnapshot(driftDefinition.getId(),
                        snapshot.getVersion(), snapshot.getVersion());
                    File deltaFile = new File(currentSnapshotFile.getParentFile(), DriftDetector.FILE_CHANGESET_DELTA);
                    Headers deltaHeaders = createHeaders(resource.getId(), driftDefinition);
                    deltaHeaders.setVersion(snapshot.getVersion());
                    deltaHeaders.setType(DRIFT);
View Full Code Here

            log.warn("changeset[resourceId: " + resourceId + ", driftDefinition: " + driftDefinition.getName()
                + "] was not found. Cancelling request to send change set " + "to server");
            return;
        }

        DriftServerService driftServer = pluginContainerConfiguration.getServerServices().getDriftServerService();

        String fileName = "changeset_" + System.currentTimeMillis() + ".zip";
        final File zipFile = new File(changeSetFile.getParentFile(), fileName);

        try {
            ZipOutputStream stream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
            FileInputStream fis = new FileInputStream(changeSetFile);
            stream.putNextEntry(new ZipEntry(changeSetFile.getName()));
            StreamUtil.copy(fis, stream, true);
        } catch (IOException e) {
            zipFile.delete();
            throw new DriftDetectionException("Failed to create change set zip file " + zipFile.getPath(), e);
            //        } finally {
            //            try {
            //                if (stream != null) {
            //                    stream.close();
            //                }
            //            } catch (IOException e) {
            //                log.warn("An error occurred while trying to close change set zip file output stream", e);
            //            }
        }

        try {
            driftServer.sendChangesetZip(resourceId, zipFile.length(), remoteInputStream(new BufferedInputStream(
                new FileInputStream(zipFile))));
        } catch (IOException e) {
            throw new DriftDetectionException("Failed to set change set for " + toString(resourceId, driftDefinition)
                + " to server");
        } catch (RuntimeException e) {
View Full Code Here

        try {
            int startIndex = "content_".length();
            int endIndex = contentZipFile.getName().indexOf(".");
            String token = contentZipFile.getName().substring(startIndex, endIndex);

            DriftServerService driftServer = pluginContainerConfiguration.getServerServices().getDriftServerService();
            driftServer.sendFilesZip(resourceId, driftDefName, token, contentZipFile.length(),
                remoteInputStream(new BufferedInputStream(new FileInputStream(contentZipFile))));
        } catch (FileNotFoundException e) {
            log.error("An error occurred while trying to send change set content zip file " + contentZipFile.getPath()
                + " to server.", e);
        }
View Full Code Here

        }
    }

    @Override
    public void repeatChangeSet(int resourceId, String driftDefName, int version) {
        DriftServerService driftServer = pluginContainerConfiguration.getServerServices().getDriftServerService();
        driftServer.repeatChangeSet(resourceId, driftDefName, version);
    }
View Full Code Here

    @Override
    public void reportMissingBaseDir(int resourceId, DriftDefinition driftDefinition) {
        if (log.isDebugEnabled()) {
            log.debug("Reporting to server missing base directory for " + toString(resourceId, driftDefinition));
        }
        DriftServerService driftServer = pluginContainerConfiguration.getServerServices().getDriftServerService();
        driftServer.updateCompliance(resourceId, driftDefinition.getName(), OUT_OF_COMPLIANCE_NO_BASEDIR);
    }
View Full Code Here

TOP

Related Classes of org.rhq.core.clientapi.server.drift.DriftServerService

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.