Search in sources :

Example 6 with MdsException

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");
}
Also used : Bundle(org.osgi.framework.Bundle) MdsException(org.motechproject.mds.exception.MdsException) BundleException(org.osgi.framework.BundleException)

Example 7 with MdsException

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");
}
Also used : Bundle(org.osgi.framework.Bundle) MdsException(org.motechproject.mds.exception.MdsException) BundleException(org.osgi.framework.BundleException)

Example 8 with MdsException

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");
}
Also used : Bundle(org.osgi.framework.Bundle) MdsException(org.motechproject.mds.exception.MdsException) BundleException(org.osgi.framework.BundleException)

Example 9 with MdsException

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);
    }
}
Also used : MdsException(org.motechproject.mds.exception.MdsException) IOException(java.io.IOException) File(java.io.File)

Example 10 with MdsException

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());
    }
}
Also used : Extension(javax.jdo.annotations.Extension) Version(javax.jdo.annotations.Version) VersionMetadata(javax.jdo.metadata.VersionMetadata) MdsException(org.motechproject.mds.exception.MdsException)

Aggregations

MdsException (org.motechproject.mds.exception.MdsException)10 Bundle (org.osgi.framework.Bundle)6 BundleException (org.osgi.framework.BundleException)5 IOException (java.io.IOException)3 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Extension (javax.jdo.annotations.Extension)1 Version (javax.jdo.annotations.Version)1 VersionMetadata (javax.jdo.metadata.VersionMetadata)1 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)1 StateManagerImpl (org.datanucleus.state.StateManagerImpl)1 EntityProcessorOutput (org.motechproject.mds.annotations.internal.EntityProcessorOutput)1 EntityDto (org.motechproject.mds.dto.EntityDto)1 MdsEntityWireException (org.motechproject.mds.exception.init.MdsEntityWireException)1