use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.
the class DescriptorServiceImpl method onLicenseChange.
@Override
public void onLicenseChange(final LicenseDescriptor licenseDescriptor) {
synchronized (licenseLock) {
logger.debug("Received changed license descriptor: " + licenseDescriptor);
RetryingTransactionCallback<RepoUsage> updateLicenseCallback = new RetryingTransactionCallback<RepoUsage>() {
public RepoUsage execute() {
// Configure the license restrictions
RepoUsage.LicenseMode newMode = licenseDescriptor.getLicenseMode();
Long expiryTime = licenseDescriptor.getValidUntil() == null ? null : licenseDescriptor.getValidUntil().getTime();
RepoUsage restrictions = new RepoUsage(System.currentTimeMillis(), licenseDescriptor.getMaxUsers(), licenseDescriptor.getMaxDocs(), newMode, expiryTime, false);
repoUsageComponent.setRestrictions(restrictions);
// Reset usage upon loading the unlimited license
if (restrictions.getUsers() == null) {
repoUsageComponent.resetUsage(UsageType.USAGE_USERS);
}
if (restrictions.getDocuments() == null) {
repoUsageComponent.resetUsage(UsageType.USAGE_DOCUMENTS);
}
// persist the server descriptor values in the current repository descriptor
if (currentRepoDescriptorNullOrModeHasChanged(newMode)) {
if (logger.isDebugEnabled()) {
logger.debug("Changing license mode in current repo descriptor to: " + newMode);
}
Descriptor newRepoDescriptor = currentRepoDescriptorDAO.updateDescriptor(serverDescriptor, newMode);
setCurrentRepoDescriptor(newRepoDescriptor);
}
if (logger.isDebugEnabled()) {
logger.debug("License restrictions updated: " + restrictions);
}
return null;
}
};
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
txnHelper.setForceWritable(true);
txnHelper.doInTransaction(updateLicenseCallback);
}
}
use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.
the class DescriptorServiceImpl method bootstrap.
private void bootstrap() {
logger.debug("onBootstrap");
// We force write mode
RetryingTransactionHelper helper = transactionService.getRetryingTransactionHelper();
helper.setForceWritable(true);
// create the initial installed descriptor
RetryingTransactionCallback<Descriptor> getDescriptorCallback = new RetryingTransactionCallback<Descriptor>() {
public Descriptor execute() {
return installedRepoDescriptorDAO.getDescriptor();
}
};
Descriptor installed = helper.doInTransaction(getDescriptorCallback, false, false);
if (installed != null) {
installedRepoDescriptor = installed;
} else {
installedRepoDescriptor = new UnknownDescriptor();
}
/*
* Initialize license service if on classpath.
* If no class exists a dummy license service is used.
* Make the LicenseService available in the context.
*/
licenseService = (LicenseService) constructSpecialService("org.alfresco.enterprise.license.LicenseComponent");
if (licenseService == null) {
// No license server code - install a dummy license service instead
licenseService = new NOOPLicenseService();
}
ApplicationContext applicationContext = getApplicationContext();
if (applicationContext instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) applicationContext).getBeanFactory().registerSingleton("licenseService", licenseService);
}
// Register HeartBeat with LicenseService
licenseService.registerOnLicenseChange((LicenseChangeHandler) hbDataCollectorService);
// Now listen for future license changes
licenseService.registerOnLicenseChange(this);
try {
// Verify license has side effect of loading any new licenses
licenseService.verifyLicense();
} catch (LicenseException e) {
// Swallow Licence Exception Here
// Don't log error: It'll be reported by other means
}
;
}
use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.
the class DescriptorStartupLog method onBootstrap.
@Override
protected void onBootstrap(ApplicationEvent event) {
//
// log output of VM stats
//
Properties properties = System.getProperties();
String version = (properties.get("java.runtime.version") == null) ? "unknown" : (String) properties.get("java.runtime.version");
long maxHeap = Runtime.getRuntime().maxMemory();
float maxHeapMB = maxHeap / 1024l;
maxHeapMB = maxHeapMB / 1024l;
if (logger.isInfoEnabled()) {
logger.info(String.format("Alfresco JVM - v%s; maximum heap size %.3fMB", version, maxHeapMB));
}
if (logger.isWarnEnabled()) {
if (version.startsWith("1.2") || version.startsWith("1.3") || version.startsWith("1.4")) {
logger.warn(String.format("Alfresco JVM - WARNING - v1.5 is required; currently using v%s", version));
}
if (maxHeapMB < 500) {
logger.warn(String.format("Alfresco JVM - WARNING - maximum heap size %.3fMB is less than recommended 512MB", maxHeapMB));
}
}
// Log License Descriptors (if applicable)
LicenseDescriptor license = descriptorService.getLicenseDescriptor();
if (license != null && logger.isInfoEnabled()) {
LicenseMode licenseMode = license.getLicenseMode();
String msg = "Alfresco license: Mode " + licenseMode;
if (license.isClusterEnabled()) {
msg += ", cluster:enabled";
} else {
msg += ", NO CLUSTER";
}
String holder = license.getHolderOrganisation();
if (holder != null) {
msg += " granted to " + holder;
}
Date validUntil = license.getValidUntil();
Integer days = null;
if (validUntil != null) {
days = license.getDays();
Integer remainingDays = license.getRemainingDays();
msg += " limited to " + days + " days expiring " + validUntil + " (" + remainingDays + " days remaining).";
} else {
msg += " (does not expire).";
}
Long maxUsers = license.getMaxUsers();
if (maxUsers != null) {
msg += " User limit is " + maxUsers + ".";
}
Long maxDocs = license.getMaxDocs();
if (maxDocs != null) {
msg += " Content Object limit is " + maxDocs + ".";
}
/*
* This is an important information logging since it logs the license
*/
if ("Trial User".equals(holder) && days != null && days == 2) {
String line = "================================================================";
logger.info(line);
logger.info(msg);
logger.info(I18NUtil.getMessage(SYSTEM_INFO_NOTRAILID));
logger.info(line);
} else {
logger.info(msg);
}
}
// Log Repository Descriptors
if (logger.isInfoEnabled()) {
logger.info("Server Mode :" + serverModeProvider.getServerMode());
Descriptor serverDescriptor = descriptorService.getServerDescriptor();
Descriptor currentDescriptor = descriptorService.getCurrentRepositoryDescriptor();
Descriptor installedRepoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
String serverEdition = serverDescriptor.getEdition();
String currentVersion = currentDescriptor.getVersion();
int currentSchemaVersion = currentDescriptor.getSchema();
LicenseMode currentMode = currentDescriptor.getLicenseMode();
String installedRepoVersion = installedRepoDescriptor.getVersion();
int installedSchemaVersion = installedRepoDescriptor.getSchema();
/*
* Alfresco started
*/
Object[] params = new Object[] { serverEdition, // only append TEAM
currentMode != LicenseMode.TEAM ? "" : (" " + currentMode), (!AuthenticationUtil.isMtEnabled() ? "" : (" Multi-Tenant")), currentVersion, currentSchemaVersion, installedRepoVersion, installedSchemaVersion };
logger.info(I18NUtil.getMessage(SYSTEM_INFO_STARTUP, params));
}
// Issue a warning if the system is in read-only mode
if (logger.isWarnEnabled() && !transactionService.getAllowWrite()) {
logger.warn(I18NUtil.getMessage(SYSTEM_WARN_READONLY));
}
}
use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.
the class RepositoryDescriptorDAOImpl method updateDescriptor.
@Override
public Descriptor updateDescriptor(final Descriptor serverDescriptor, LicenseMode licenseMode) {
Descriptor descriptor = null;
try {
final NodeRef currentDescriptorNodeRef = getDescriptorNodeRef(true);
// if the node is missing but it should have been created
if (currentDescriptorNodeRef == null) {
return null;
}
// set the properties
if (!this.transactionService.isReadOnly()) {
Map<QName, Serializable> props = new HashMap<QName, Serializable>(11);
props.put(ContentModel.PROP_SYS_NAME, serverDescriptor.getName());
props.put(ContentModel.PROP_SYS_VERSION_MAJOR, serverDescriptor.getVersionMajor());
props.put(ContentModel.PROP_SYS_VERSION_MINOR, serverDescriptor.getVersionMinor());
props.put(ContentModel.PROP_SYS_VERSION_REVISION, serverDescriptor.getVersionRevision());
props.put(ContentModel.PROP_SYS_VERSION_LABEL, serverDescriptor.getVersionLabel());
props.put(ContentModel.PROP_SYS_VERSION_BUILD, serverDescriptor.getVersionBuild());
props.put(ContentModel.PROP_SYS_VERSION_SCHEMA, serverDescriptor.getSchema());
props.put(ContentModel.PROP_SYS_LICENSE_MODE, licenseMode);
// Aspect index control - stop the search system getting involved with licenses.
props.put(ContentModel.PROP_IS_CONTENT_INDEXED, false);
props.put(ContentModel.PROP_IS_INDEXED, false);
this.nodeService.addProperties(currentDescriptorNodeRef, props);
// ALF-726: v3.1.x Content Cleaner Job needs to be ported to v3.2
// In order to migrate properly, this property needs to be d:content. We will rewrite the property with the
// license update code. There is no point attempting to rewrite the property here.
final Serializable value = this.nodeService.getProperty(currentDescriptorNodeRef, ContentModel.PROP_SYS_VERSION_EDITION);
if (value == null) {
this.nodeService.setProperty(currentDescriptorNodeRef, ContentModel.PROP_SYS_VERSION_EDITION, new ContentData(null, null, 0L, null));
}
// done
if (RepositoryDescriptorDAOImpl.logger.isDebugEnabled()) {
RepositoryDescriptorDAOImpl.logger.debug("Updated current repository descriptor properties: \n" + " node: " + currentDescriptorNodeRef + "\n" + " descriptor: " + serverDescriptor);
}
}
final Map<QName, Serializable> properties = this.nodeService.getProperties(currentDescriptorNodeRef);
descriptor = new RepositoryDescriptor(properties);
} catch (final RuntimeException e) {
if (logger.isErrorEnabled()) {
logger.error("updateDescriptor: ", e);
}
throw e;
} catch (final Error e) {
if (logger.isErrorEnabled()) {
logger.error("updateDescriptor: ", e);
}
throw e;
}
return descriptor;
}
use of org.alfresco.service.descriptor.Descriptor in project alfresco-repository by Alfresco.
the class AuthoritiesDataCollectorTest method setUp.
@Before
public void setUp() {
HBDataCollectorService mockCollectorService = mock(HBDataCollectorService.class);
AuthorityService authorityService = mock(AuthorityService.class);
mockScheduler = mock(HeartBeatJobScheduler.class);
Descriptor mockDescriptor = mock(Descriptor.class);
when(mockDescriptor.getId()).thenReturn("mock_id");
DescriptorDAO descriptorDAO = mock(DescriptorDAO.class);
when(descriptorDAO.getDescriptor()).thenReturn(mockDescriptor);
authorityDataCollector = new AuthoritiesDataCollector("acs.repository.usage.authorities", "1.0", "0 0 0 ? * *", mockScheduler);
authorityDataCollector.setAuthorityService(authorityService);
authorityDataCollector.setCurrentRepoDescriptorDAO(descriptorDAO);
authorityDataCollector.setHbDataCollectorService(mockCollectorService);
collectedData = authorityDataCollector.collectData();
}
Aggregations