use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class EntitiesBundleMonitor method uninstall.
private void uninstall() {
LOGGER.info("Uninstalling the entities bundle");
try {
Bundle entitiesBundle = getEntitiesBundle();
if (entitiesBundle != null) {
entitiesBundle.uninstall();
} else {
LOGGER.warn("No entities bundle to uninstall");
}
} catch (BundleException e) {
throw new MdsException("Unable to uninstall the entities bundle", e);
}
waitUntil(new Condition() {
@Override
public boolean await() {
return !bundleUninstalled;
}
}, "uninstalled");
LOGGER.info("Uninstalled the entities bundle");
}
use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class EntitiesBundleMonitor method stopEntitiesBundle.
/**
* Stops the entities bundle and waits until it will be resolved.
*/
public void stopEntitiesBundle() {
LOGGER.info("Stopping the entities bundle");
try {
Bundle entitiesBundle = getEntitiesBundle();
if (entitiesBundle != null) {
entitiesBundle.stop();
} else {
LOGGER.warn("No entities bundle to stop");
return;
}
} catch (BundleException e) {
throw new MdsException("Unable to stop the entities bundle", e);
}
waitUntil(new Condition() {
@Override
public boolean await() {
return !isEntitiesBundleState(Bundle.RESOLVED);
}
}, "stopped");
LOGGER.info("Stopped the entities bundle");
}
use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class EntitiesBundleMonitor method update.
private void update(InputStream stream) {
LOGGER.info("Updating the entities bundle");
try {
Bundle entitiesBundle = getEntitiesBundle();
if (entitiesBundle != null) {
entitiesBundle.update(stream);
} else {
throw new MdsException("No entities bundle to update, unable to update entities");
}
} catch (BundleException e) {
throw new MdsException("Unable to update the entities bundle", e);
}
waitUntil(new Condition() {
@Override
public boolean await() {
return !isEntitiesBundleState(Bundle.INSTALLED);
}
}, "updated");
LOGGER.info("Updated the entities bundle");
}
use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class JarGeneratorServiceImpl method regenerateMdsDataBundle.
private synchronized void regenerateMdsDataBundle(SchemaHolder schemaHolder, boolean startBundle, String... moduleNames) {
LOGGER.info("Regenerating the mds entities bundle");
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
clearModulesCache(moduleNames);
cleanEntitiesBundleCachedClasses();
boolean constructed = mdsConstructor.constructEntities(schemaHolder);
if (!constructed) {
return;
}
LOGGER.info("Updating mds data provider");
mdsDataProvider.updateDataProvider(schemaHolder);
File dest = new File(monitor.bundleLocation());
if (dest.exists()) {
// proceed when the bundles context is ready, we want the context processors to finish
LOGGER.info("Waiting for entities context");
monitor.waitForEntitiesContext();
}
File tmpBundleFile;
try {
LOGGER.info("Generating bundle jar");
tmpBundleFile = generate(schemaHolder);
LOGGER.info("Generated bundle jar");
} catch (IOException e) {
throw new MdsException("Unable to generate entities bundle", e);
}
FileUtils.deleteQuietly(dest);
try {
FileUtils.copyFile(tmpBundleFile, dest);
} catch (IOException e) {
LOGGER.error("Unable to copy the mds-entities bundle to the bundle directory. Installing from temp directory", e);
// install from temp directory
dest = tmpBundleFile;
}
monitor.stopEntitiesBundle();
// In case of some core bundles, we must first stop some modules in order to avoid problems during refresh
stopModulesForCoreBundleRefresh(moduleNames);
try {
monitor.start(dest, false);
} finally {
FileUtils.deleteQuietly(tmpBundleFile);
}
// We must clear module names which was restarted after failing
mdsOsgiBundleApplicationContextListener.clearBundlesSet();
refreshModules(moduleNames);
if (startBundle) {
monitor.start();
}
// Start bundles again if we stopped them manually
startModulesForCoreBundleRefresh(moduleNames);
// Give framework some time before returning to the caller
ThreadSuspender.sleep(2000);
} finally {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
use of org.motechproject.mds.exception.MdsException in project motech by motech.
the class EntityMetadataBuilderImpl method addVersioningMetadata.
private void addVersioningMetadata(ClassMetadata cmd, Class<?> definition) {
Class<Version> ann = ReflectionsUtil.getAnnotationClass(definition, Version.class);
Version versionAnnotation = AnnotationUtils.findAnnotation(definition, ann);
if (versionAnnotation != null) {
VersionMetadata vmd = cmd.newVersionMetadata();
vmd.setColumn(versionAnnotation.column());
vmd.setStrategy(versionAnnotation.strategy());
if (versionAnnotation.extensions().length == 0 || !"field-name".equals(versionAnnotation.extensions()[0].key())) {
throw new MdsException(String.format("Cannot create metadata fo %s. Extension not found in @Version annotation.", cmd.getName()));
}
Extension extension = versionAnnotation.extensions()[0];
vmd.newExtensionMetadata(DATANUCLEUS, "field-name", extension.value());
}
}
Aggregations