Search in sources :

Example 16 with Descriptor

use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.

the class CMISConnector method createRepositoryInfo.

/**
 * Creates the repository info object.
 */
private RepositoryInfo createRepositoryInfo(CmisVersion cmisVersion) {
    Descriptor currentDescriptor = descriptorService.getCurrentRepositoryDescriptor();
    // get change token
    boolean auditEnabled = auditService.isAuditEnabled(CMIS_CHANGELOG_AUDIT_APPLICATION, "/" + CMIS_CHANGELOG_AUDIT_APPLICATION);
    String latestChangeLogToken = null;
    if (auditEnabled) {
        EntryIdCallback auditQueryCallback = new EntryIdCallback(false);
        AuditQueryParameters params = new AuditQueryParameters();
        params.setApplicationName(CMIS_CHANGELOG_AUDIT_APPLICATION);
        params.setForward(false);
        auditService.auditQuery(auditQueryCallback, params, 1);
        String entryId = auditQueryCallback.getEntryId();
        // MNT-13529
        // add initial change log token
        latestChangeLogToken = entryId == null ? "0" : entryId;
    }
    // compile repository info
    RepositoryInfoImpl ri = new RepositoryInfoImpl();
    ri.setId(currentDescriptor.getId());
    ri.setName(currentDescriptor.getName());
    ri.setDescription(currentDescriptor.getName());
    ri.setVendorName("Alfresco");
    ri.setProductName("Alfresco " + descriptorService.getServerDescriptor().getEdition());
    ri.setProductVersion(currentDescriptor.getVersion());
    NodeRef rootNodeRef = getRootNodeRef();
    ri.setRootFolder(constructObjectId(rootNodeRef, null));
    ri.setCmisVersion(cmisVersion);
    ri.setChangesIncomplete(true);
    ri.setChangesOnType(Arrays.asList(new BaseTypeId[] { BaseTypeId.CMIS_DOCUMENT, BaseTypeId.CMIS_FOLDER }));
    ri.setLatestChangeLogToken(latestChangeLogToken);
    ri.setPrincipalAnonymous(AuthenticationUtil.getGuestUserName());
    ri.setPrincipalAnyone(PermissionService.ALL_AUTHORITIES);
    RepositoryCapabilitiesImpl repCap = new RepositoryCapabilitiesImpl();
    ri.setCapabilities(repCap);
    repCap.setAllVersionsSearchable(false);
    repCap.setCapabilityAcl(CapabilityAcl.MANAGE);
    repCap.setCapabilityChanges(auditEnabled ? CapabilityChanges.OBJECTIDSONLY : CapabilityChanges.NONE);
    repCap.setCapabilityContentStreamUpdates(CapabilityContentStreamUpdates.ANYTIME);
    repCap.setCapabilityJoin(CapabilityJoin.NONE);
    repCap.setCapabilityQuery(CapabilityQuery.BOTHCOMBINED);
    repCap.setCapabilityRendition(CapabilityRenditions.READ);
    repCap.setIsPwcSearchable(false);
    repCap.setIsPwcUpdatable(true);
    repCap.setSupportsGetDescendants(true);
    repCap.setSupportsGetFolderTree(true);
    repCap.setSupportsMultifiling(true);
    repCap.setSupportsUnfiling(false);
    repCap.setSupportsVersionSpecificFiling(false);
    AclCapabilitiesDataImpl aclCap = new AclCapabilitiesDataImpl();
    ri.setAclCapabilities(aclCap);
    aclCap.setAclPropagation(AclPropagation.PROPAGATE);
    aclCap.setSupportedPermissions(SupportedPermissions.BOTH);
    aclCap.setPermissionDefinitionData(repositoryPermissions);
    aclCap.setPermissionMappingData(permissionMappings);
    return ri;
}
Also used : RepositoryInfoImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryInfoImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepositoryCapabilitiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryCapabilitiesImpl) AuditQueryParameters(org.alfresco.service.cmr.audit.AuditQueryParameters) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Descriptor(org.alfresco.service.descriptor.Descriptor) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) AclCapabilitiesDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AclCapabilitiesDataImpl)

Example 17 with Descriptor

use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.

the class DescriptorServiceTest method testServerDescriptor.

/**
 * Test server decriptor
 */
@Test
public void testServerDescriptor() {
    ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    DescriptorService descriptorService = registry.getDescriptorService();
    Descriptor serverDescriptor = descriptorService.getServerDescriptor();
    String major = serverDescriptor.getVersionMajor();
    String minor = serverDescriptor.getVersionMinor();
    String revision = serverDescriptor.getVersionRevision();
    String label = serverDescriptor.getVersionLabel();
    String build = serverDescriptor.getVersionBuild();
    String edition = serverDescriptor.getEdition();
    String id = serverDescriptor.getId();
    String version = major + "." + minor + "." + revision;
    version = buildVersionString(version, label, build);
    assertEquals(version, serverDescriptor.getVersion());
    int schemaVersion = serverDescriptor.getSchema();
    assertTrue("Server schema version must be greater than 0", schemaVersion > 0);
    assertNotNull("edition is null", edition);
    assertEquals("id ", id, "Unknown");
}
Also used : Descriptor(org.alfresco.service.descriptor.Descriptor) ServiceRegistry(org.alfresco.service.ServiceRegistry) DescriptorService(org.alfresco.service.descriptor.DescriptorService) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 18 with Descriptor

use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.

the class DescriptorServiceTest method testCompareDescriptors.

@Test
public void testCompareDescriptors() {
    ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    DescriptorService descriptorService = registry.getDescriptorService();
    Descriptor serverDescriptor = descriptorService.getServerDescriptor();
    Descriptor repoDescriptor = descriptorService.getCurrentRepositoryDescriptor();
    String major1 = repoDescriptor.getVersionMajor();
    String minor1 = repoDescriptor.getVersionMinor();
    String revision1 = repoDescriptor.getVersionRevision();
    String label1 = repoDescriptor.getVersionLabel();
    String build1 = repoDescriptor.getVersionBuild();
    String id1 = repoDescriptor.getId();
    String major2 = serverDescriptor.getVersionMajor();
    String minor2 = serverDescriptor.getVersionMinor();
    String revision2 = serverDescriptor.getVersionRevision();
    String label2 = serverDescriptor.getVersionLabel();
    String build2 = serverDescriptor.getVersionBuild();
    String id2 = serverDescriptor.getId();
    assertEquals("major version different", major1, major2);
    assertEquals("minor version different", minor1, minor2);
    assertEquals("revision version different", revision1, revision2);
    assertEquals("label version different", label1, label2);
    assertEquals("build version different", build1, build2);
}
Also used : Descriptor(org.alfresco.service.descriptor.Descriptor) ServiceRegistry(org.alfresco.service.ServiceRegistry) DescriptorService(org.alfresco.service.descriptor.DescriptorService) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 19 with Descriptor

use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.

the class TransferServiceImpl2 method transferImpl.

private TransferEndEvent transferImpl(String targetName, final TransferDefinition definition, final TransferEventProcessor eventProcessor) throws TransferFailureException {
    if (logger.isDebugEnabled()) {
        logger.debug("transfer started to :" + targetName);
    }
    // transfer end event
    TransferEndEvent endEvent = null;
    Exception failureException = null;
    TransferTarget target = null;
    Transfer transfer = null;
    final List<TransferEvent> transferReportEvents = new LinkedList<TransferEvent>();
    NodeRef sourceReport = null;
    NodeRef destinationReport = null;
    File manifest = null;
    File requisite = null;
    int pollRetries = 0;
    int pollPosition = -1;
    boolean cancelled = false;
    Descriptor currentDescriptor = descriptorService.getCurrentRepositoryDescriptor();
    Descriptor serverDescriptor = descriptorService.getServerDescriptor();
    final String localRepositoryId = currentDescriptor.getId();
    TransferVersion fromVersion = new TransferVersionImpl(serverDescriptor);
    // Wire in the transferReport - so any callbacks are stored in transferReport
    TransferCallback reportCallback = new TransferCallback() {

        public void processEvent(TransferEvent event) {
            transferReportEvents.add(event);
        }
    };
    eventProcessor.addObserver(reportCallback);
    TransferContext transferContext = new TransferContext();
    // start transfer
    ClientTransferState clientState = ClientTransferState.Begin;
    while (clientState != ClientTransferState.Exit) {
        try {
            switch(clientState) {
                case Begin:
                    {
                        eventProcessor.start();
                        manifest = createManifest(definition, localRepositoryId, fromVersion, transferContext);
                        logger.debug("transfer begin");
                        target = getTransferTarget(targetName);
                        checkTargetEnabled(target);
                        transfer = transmitter.begin(target, localRepositoryId, fromVersion);
                        String transferId = transfer.getTransferId();
                        TransferStatus status = new TransferStatus();
                        transferMonitoring.put(transferId, status);
                        logger.debug("transfer begun transferId:" + transferId);
                        eventProcessor.begin(transferId);
                        checkCancel(transferId);
                        // next state
                        clientState = ClientTransferState.Prepare;
                        break;
                    }
                case Prepare:
                    {
                        // check alfresco versions are compatible
                        TransferVersion toVersion = transfer.getToVersion();
                        if (!this.transferVersionChecker.checkTransferVersions(fromVersion, toVersion)) {
                            throw new TransferException(MSG_INCOMPATIBLE_VERSIONS, new Object[] { transfer.getTransferId(), fromVersion, toVersion });
                        }
                        // send Manifest, get the requsite back.
                        eventProcessor.sendSnapshot(1, 1);
                        requisite = createRequisiteFile();
                        FileOutputStream reqOutput = new FileOutputStream(requisite);
                        transmitter.sendManifest(transfer, manifest, reqOutput);
                        logger.debug("manifest sent");
                        checkCancel(transfer.getTransferId());
                        if (logger.isDebugEnabled()) {
                            logger.debug("requisite file written to local filesystem");
                            try {
                                outputFile(requisite);
                            } catch (IOException error) {
                                // This is debug code - so an exception thrown while debugging
                                logger.debug("error while outputting snapshotFile");
                                error.printStackTrace();
                            }
                        }
                        sendContent(transfer, definition, eventProcessor, manifest, requisite);
                        logger.debug("content sending finished");
                        checkCancel(transfer.getTransferId());
                        // prepare
                        eventProcessor.prepare();
                        transmitter.prepare(transfer);
                        checkCancel(transfer.getTransferId());
                        // next state
                        clientState = ClientTransferState.Commit;
                        break;
                    }
                case Commit:
                    {
                        logger.debug("about to start committing transferId:" + transfer.getTransferId());
                        eventProcessor.commit();
                        transmitter.commit(transfer);
                        logger.debug("committing transferId:" + transfer.getTransferId());
                        checkCancel(transfer.getTransferId());
                        // next state
                        clientState = ClientTransferState.Poll;
                        break;
                    }
                case Poll:
                    {
                        TransferProgress progress = null;
                        try {
                            progress = transmitter.getStatus(transfer);
                            // reset retries for next poll
                            pollRetries = 0;
                        } catch (TransferException e) {
                            pollRetries++;
                            if (pollRetries == 3) {
                                throw new TransferException(MSG_FAILED_TO_GET_TRANSFER_STATUS, new Object[] { target.getName() });
                            }
                        }
                        // check status
                        if (progress.getStatus() == TransferProgress.Status.ERROR) {
                            Throwable targetError = progress.getError();
                            // NOTE: it's possible the error is not returned from pre v3.4 target repositories
                            if (targetError == null) {
                                targetError = new TransferException(MSG_UNKNOWN_TARGET_ERROR);
                            }
                            if (Exception.class.isAssignableFrom(targetError.getClass())) {
                                failureException = (Exception) targetError;
                            } else {
                                failureException = new TransferException(MSG_TARGET_ERROR, new Object[] { targetError.getMessage() }, targetError);
                            }
                            clientState = ClientTransferState.Finished;
                            break;
                        } else if (progress.getStatus() == TransferProgress.Status.CANCELLED) {
                            cancelled = true;
                            clientState = ClientTransferState.Finished;
                            break;
                        }
                        // notify transfer progress
                        if (progress.getCurrentPosition() != pollPosition) {
                            pollPosition = progress.getCurrentPosition();
                            logger.debug("committing :" + pollPosition);
                            eventProcessor.committing(progress.getEndPosition(), pollPosition);
                        }
                        if (progress.getStatus() == TransferProgress.Status.COMPLETE) {
                            clientState = ClientTransferState.Finished;
                            break;
                        }
                        checkCancel(transfer.getTransferId());
                        // sleep before next poll
                        try {
                            Thread.sleep(commitPollDelay);
                        } catch (InterruptedException e) {
                        // carry on
                        }
                        break;
                    }
                case Cancel:
                    {
                        logger.debug("Abort - waiting for target confirmation of cancel");
                        transmitter.abort(transfer);
                        // next state... poll for confirmation of cancel from target
                        clientState = ClientTransferState.Poll;
                        break;
                    }
                case Finished:
                    {
                        try {
                            TransferEndEventImpl endEventImpl = null;
                            String reportName = null;
                            try {
                                if (failureException != null) {
                                    logger.debug("TransferException - unable to transfer", failureException);
                                    TransferEventError errorEvent = new TransferEventError();
                                    errorEvent.setTransferState(TransferEvent.TransferState.ERROR);
                                    errorEvent.setException(failureException);
                                    errorEvent.setMessage(failureException.getMessage());
                                    endEventImpl = errorEvent;
                                    reportName = "error";
                                } else if (cancelled) {
                                    endEventImpl = new TransferEventCancelled();
                                    endEventImpl.setTransferState(TransferEvent.TransferState.CANCELLED);
                                    endEventImpl.setMessage("cancelled");
                                    reportName = "cancelled";
                                } else {
                                    logger.debug("committed transferId:" + transfer.getTransferId());
                                    endEventImpl = new TransferEventSuccess();
                                    endEventImpl.setTransferState(TransferEvent.TransferState.SUCCESS);
                                    endEventImpl.setMessage("success");
                                    reportName = "success";
                                }
                                // manually add the terminal event to the transfer report event list
                                transferReportEvents.add(endEventImpl);
                            } catch (Exception e) {
                                // report this failure as last resort
                                failureException = e;
                                reportName = "error";
                                logger.warn("Exception - unable to notify end transfer state", e);
                            }
                            reportName += "_" + new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
                            try {
                                if (transfer != null) {
                                    logger.debug("now pull back the destination transfer report");
                                    destinationReport = persistDestinationTransferReport(reportName, transfer, target);
                                    if (destinationReport != null) {
                                        eventProcessor.writeReport(destinationReport, TransferEventReport.ReportType.DESTINATION, endEventImpl.getTransferState());
                                    }
                                }
                                logger.debug("now persist the client side transfer report");
                                sourceReport = persistTransferReport(reportName, transfer, target, definition, transferReportEvents, manifest, failureException);
                                if (sourceReport != null) {
                                    eventProcessor.writeReport(sourceReport, TransferEventReport.ReportType.SOURCE, endEventImpl.getTransferState());
                                }
                            } catch (Exception e) {
                                logger.warn("Exception - unable to write transfer reports", e);
                            }
                            try {
                                endEventImpl.setLast(true);
                                endEventImpl.setSourceReport(sourceReport);
                                endEventImpl.setDestinationReport(destinationReport);
                                endEvent = endEventImpl;
                                eventProcessor.end(endEvent);
                            } catch (Exception e) {
                                // report this failure as last resort
                                failureException = e;
                                logger.warn("Exception - unable to notify end transfer state", e);
                            }
                        } finally {
                            clientState = ClientTransferState.Exit;
                        }
                    }
            }
        } catch (TransferCancelledException e) {
            logger.debug("Interrupted by transfer cancel request from client");
            clientState = ClientTransferState.Cancel;
        } catch (Exception e) {
            logger.debug("Exception - unable to transfer", e);
            /**
             * Save the first exception that we encounter.
             */
            if (failureException == null) {
                failureException = e;
            }
            if (transfer != null && (clientState == ClientTransferState.Begin || clientState == ClientTransferState.Prepare || clientState == ClientTransferState.Commit)) {
                // we must first inform the target repository that a client failure has occurred to allow it to
                // clean up appropriately, too
                clientState = ClientTransferState.Cancel;
            } else {
                clientState = ClientTransferState.Finished;
            }
        }
    }
    try {
        if (endEvent == null) {
            TransferEventError error = new TransferEventError();
            error.setTransferState(TransferEvent.TransferState.ERROR);
            TransferFailureException endException = new TransferFailureException(error);
            error.setMessage(endException.getMessage());
            error.setException(endException);
            error.setSourceReport(sourceReport);
            error.setDestinationReport(destinationReport);
            error.setLast(true);
            endEvent = error;
        }
        if (endEvent instanceof TransferEventError) {
            TransferEventError endError = (TransferEventError) endEvent;
            throw new TransferFailureException(endError);
        }
        return endEvent;
    } finally {
        // clean up
        if (transfer != null) {
            transferMonitoring.remove(transfer.getTransferId());
        }
        if (manifest != null) {
            manifest.delete();
            logger.debug("manifest file deleted");
        }
        if (requisite != null) {
            requisite.delete();
            logger.debug("requisite file deleted");
        }
    }
}
Also used : TransferCancelledException(org.alfresco.service.cmr.transfer.TransferCancelledException) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget) NodeRef(org.alfresco.service.cmr.repository.NodeRef) TransferEventSuccess(org.alfresco.service.cmr.transfer.TransferEventSuccess) TransferEventError(org.alfresco.service.cmr.transfer.TransferEventError) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException) TransferEndEvent(org.alfresco.service.cmr.transfer.TransferEndEvent) TransferEvent(org.alfresco.service.cmr.transfer.TransferEvent) TransferEventCancelled(org.alfresco.service.cmr.transfer.TransferEventCancelled) IOException(java.io.IOException) TransferCancelledException(org.alfresco.service.cmr.transfer.TransferCancelledException) TransferFailureException(org.alfresco.service.cmr.transfer.TransferFailureException) TransferException(org.alfresco.service.cmr.transfer.TransferException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LinkedList(java.util.LinkedList) TransferCallback(org.alfresco.service.cmr.transfer.TransferCallback) Date(java.util.Date) TransferProgress(org.alfresco.service.cmr.transfer.TransferProgress) TransferException(org.alfresco.service.cmr.transfer.TransferException) FileOutputStream(java.io.FileOutputStream) Descriptor(org.alfresco.service.descriptor.Descriptor) File(java.io.File) TransferVersion(org.alfresco.service.cmr.transfer.TransferVersion) SimpleDateFormat(java.text.SimpleDateFormat)

Example 20 with Descriptor

use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.

the class InfoDataCollector method collectData.

@Override
public List<HBData> collectData() {
    logger.debug("Preparing repository info data...");
    final Descriptor serverDescriptor = this.serverDescriptorDAO.getDescriptor();
    Map<String, Object> infoValues = new HashMap<>();
    infoValues.put("repoName", serverDescriptor.getName());
    Map<String, Object> version = new HashMap<>();
    version.put("full", serverDescriptor.getVersion());
    version.put("servicePack", serverDescriptor.getVersionMajor() + "." + serverDescriptor.getVersionMinor());
    version.put("major", serverDescriptor.getVersionMajor());
    version.put("minor", serverDescriptor.getVersionMinor());
    version.put("patch", serverDescriptor.getVersionRevision());
    version.put("build", serverDescriptor.getVersionBuild());
    String hotfix = serverDescriptor.getVersionLabel();
    if (hotfix != null && hotfix.length() > 0) {
        version.put("hotfix", hotfix.startsWith(".") ? hotfix.substring(1) : hotfix);
    }
    infoValues.put("version", version);
    infoValues.put("schema", new Integer(serverDescriptor.getSchema()));
    infoValues.put("edition", serverDescriptor.getEdition());
    infoValues.put("deploymentMethod", deploymentMethodProvider.getDeploymentMethod().toString());
    infoValues.put("osVendor", System.getProperty("os.name"));
    infoValues.put("osVersion", System.getProperty("os.version"));
    infoValues.put("osArch", System.getProperty("os.arch"));
    infoValues.put("javaVendor", System.getProperty("java.vendor"));
    infoValues.put("javaVersion", System.getProperty("java.version"));
    infoValues.put("userLanguage", Locale.getDefault().getLanguage());
    infoValues.put("userTimezone", TimeZone.getDefault().getID());
    infoValues.put("userUTCOffset", OffsetDateTime.now().getOffset().getId().replaceAll("Z", "+00.00"));
    if (servletContext != null) {
        infoValues.put("serverInfo", servletContext.getServerInfo());
    } else
        infoValues.put("serverInfo", null);
    try (Connection con = dataSource.getConnection()) {
        DatabaseMetaData dbmeta = con.getMetaData();
        Map<String, Object> db = new HashMap<>();
        db.put("vendor", dbmeta.getDatabaseProductName());
        db.put("version", dbmeta.getDatabaseProductVersion());
        db.put("driverName", dbmeta.getDriverName());
        db.put("driverVersion", dbmeta.getDriverVersion());
        infoValues.put("db", db);
    } catch (SQLException e) {
    // No need to log exception if the data cannot be retrieved
    }
    HBData infoData = new HBData(this.currentRepoDescriptorDAO.getDescriptor().getId(), this.getCollectorId(), this.getCollectorVersion(), new Date(), infoValues);
    return Arrays.asList(infoData);
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Descriptor(org.alfresco.service.descriptor.Descriptor) HBData(org.alfresco.heartbeat.datasender.HBData) DatabaseMetaData(java.sql.DatabaseMetaData) Date(java.util.Date)

Aggregations

Descriptor (org.alfresco.service.descriptor.Descriptor)26 DescriptorService (org.alfresco.service.descriptor.DescriptorService)7 HeartBeatJobScheduler (org.alfresco.heartbeat.jobs.HeartBeatJobScheduler)6 DescriptorDAO (org.alfresco.repo.descriptor.DescriptorDAO)6 HBDataCollectorService (org.alfresco.service.cmr.repository.HBDataCollectorService)6 Before (org.junit.Before)6 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)5 ServiceRegistry (org.alfresco.service.ServiceRegistry)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 LicenseDescriptor (org.alfresco.service.license.LicenseDescriptor)4 BaseSpringTest (org.alfresco.util.BaseSpringTest)4 Test (org.junit.Test)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2