Search in sources :

Example 66 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.

the class CaptureAgentStateServiceImpl method updated.

/**
 * {@inheritDoc}
 *
 * @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
 */
@Override
public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
    // Get the agent properties
    String nameConfig = (String) properties.get("id");
    if (isBlank(nameConfig))
        throw new ConfigurationException("id", "must be specified");
    nameConfig = nameConfig.trim();
    String urlConfig = (String) properties.get("url");
    if (isBlank(urlConfig))
        throw new ConfigurationException("url", "must be specified");
    urlConfig = urlConfig.trim();
    String orgConfig = (String) properties.get("organization");
    if (isBlank(orgConfig))
        throw new ConfigurationException("organization", "must be specified");
    orgConfig = orgConfig.trim();
    String schedulerRolesConfig = (String) properties.get("schedulerRoles");
    if (isBlank(schedulerRolesConfig))
        throw new ConfigurationException("schedulerRoles", "must be specified");
    String[] schedulerRoles = schedulerRolesConfig.trim().split(",");
    // If we don't already have a mapping for this PID, create one
    if (!pidMap.containsKey(pid)) {
        pidMap.put(pid, nameConfig);
    }
    AgentImpl agent;
    try {
        agent = getAgent(nameConfig, orgConfig);
        agent.setUrl(urlConfig);
        agent.setState(UNKNOWN);
    } catch (NotFoundException e) {
        agent = new AgentImpl(nameConfig, orgConfig, UNKNOWN, urlConfig, new Properties());
    }
    for (String role : schedulerRoles) {
        agent.schedulerRoles.add(role.trim());
    }
    // Update the database
    logger.info("Roles '{}' may schedule '{}'", schedulerRolesConfig, agent.name);
    updateAgentInDatabase(agent);
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) NotFoundException(org.opencastproject.util.NotFoundException) Properties(java.util.Properties)

Example 67 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.

the class RedirectingMediaPackageSerializer method updated.

/**
 * {@inheritDoc}
 *
 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
 */
@SuppressWarnings("rawtypes")
@Override
public void updated(Dictionary properties) throws ConfigurationException {
    if (properties == null) {
        logger.warn("Mediapackage serializer is unconfigured");
        return;
    }
    // Clear the current set of redirects
    redirects.clear();
    String sourceKey = null;
    String destinationKey = null;
    int i = 1;
    while (true) {
        // Create the configuration keys
        sourceKey = new StringBuilder(OPT_SOURCE_PREFIX).append(".").append(i).toString();
        destinationKey = new StringBuilder(OPT_DESINATION_PREFIX).append(".").append(i).toString();
        logger.debug("Looking for configuration of {} and {}", sourceKey, destinationKey);
        // Read the source and destination prefixes
        String sourcePrefixOpt = StringUtils.trimToNull((String) properties.get(sourceKey));
        String destinationPrefixOpt = StringUtils.trimToNull((String) properties.get(destinationKey));
        // Has the rewriter been fully configured
        if (sourcePrefixOpt == null || destinationPrefixOpt == null) {
            logger.info("Mediapackage serializer configured to transparent mode");
            break;
        }
        URI sourcePrefix = null;
        URI destinationPrefix = null;
        try {
            sourcePrefix = new URI(sourcePrefixOpt);
        } catch (URISyntaxException e) {
            throw new ConfigurationException(sourceKey, e.getMessage());
        }
        // Read the source prefix
        try {
            destinationPrefix = new URI(destinationPrefixOpt);
        } catch (URISyntaxException e) {
            throw new ConfigurationException(destinationKey, e.getMessage());
        }
        // Store the redirect
        try {
            addRedirect(destinationPrefix, sourcePrefix);
            logger.info("Mediapackage serializer will rewrite element uris from starting with '{}' to start with '{}'", destinationPrefix, sourcePrefix);
        } catch (IllegalStateException e) {
            throw new ConfigurationException(sourceKey, e.getMessage());
        }
        i++;
    }
    // Has the rewriter been fully configured
    if (redirects.size() == 0) {
        logger.info("Mediapackage serializer configured to transparent mode");
        return;
    }
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 68 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.

the class CaptureNowProlongingService method updated.

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    // Read configuration for the default initial duration
    try {
        initialTime = Integer.parseInt(StringUtils.defaultIfBlank((String) properties.get(CFG_KEY_INITIAL_TIME), "300"));
    } catch (NumberFormatException e) {
        throw new ConfigurationException(CFG_KEY_INITIAL_TIME, "Not an integer", e);
    }
    initialTime = Math.max(initialTime, 90) * 1000;
    // Read configuration for the prolonging time
    try {
        prolongingTime = Integer.parseInt(StringUtils.defaultIfBlank((String) properties.get(CFG_KEY_PROLONGING_TIME), "300"));
    } catch (NumberFormatException e) {
        throw new ConfigurationException(CFG_KEY_PROLONGING_TIME, "Not an integer", e);
    }
    prolongingTime = Math.max(prolongingTime, 90) * 1000;
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 69 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.

the class YouTubeV3PublicationServiceImpl method updated.

@Override
public void updated(final Dictionary props) throws ConfigurationException {
    properties.merge(props);
    enabled = Boolean.valueOf((String) properties.get(YOUTUBE_ENABLED_KEY));
    final String dataStore = YouTubeUtils.get(properties, YouTubeKey.credentialDatastore);
    try {
        if (enabled) {
            final ClientCredentials clientCredentials = new ClientCredentials();
            clientCredentials.setCredentialDatastore(dataStore);
            final String path = YouTubeUtils.get(properties, YouTubeKey.clientSecretsV3);
            File secretsFile = new File(path);
            if (secretsFile.exists() && !secretsFile.isDirectory()) {
                clientCredentials.setClientSecrets(secretsFile);
                clientCredentials.setDataStoreDirectory(YouTubeUtils.get(properties, YouTubeKey.dataStore));
                // 
                youTubeService.initialize(clientCredentials);
                // 
                tags = StringUtils.split(YouTubeUtils.get(properties, YouTubeKey.keywords), ',');
                defaultPlaylist = YouTubeUtils.get(properties, YouTubeKey.defaultPlaylist);
                makeVideosPrivate = StringUtils.containsIgnoreCase(YouTubeUtils.get(properties, YouTubeKey.makeVideosPrivate), "true");
                defaultMaxFieldLength(YouTubeUtils.get(properties, YouTubeKey.maxFieldLength, false));
            } else {
                logger.warn("Client information file does not exist: " + path);
            }
        } else {
            logger.info("YouTube v3 publication service is disabled");
        }
    } catch (final Exception e) {
        throw new ConfigurationException("Failed to load YouTube v3 properties", dataStore, e);
    }
    youtubePublishJobLoad = LoadUtil.getConfiguredLoadValue(properties, YOUTUBE_PUBLISH_LOAD_KEY, DEFAULT_YOUTUBE_PUBLISH_JOB_LOAD, serviceRegistry);
    youtubeRetractJobLoad = LoadUtil.getConfiguredLoadValue(properties, YOUTUBE_RETRACT_LOAD_KEY, DEFAULT_YOUTUBE_RETRACT_JOB_LOAD, serviceRegistry);
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) ClientCredentials(org.opencastproject.publication.youtube.auth.ClientCredentials) File(java.io.File) PublicationException(org.opencastproject.publication.api.PublicationException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 70 with ConfigurationException

use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.

the class WorkflowServiceImpl method updated.

/**
 * {@inheritDoc}
 *
 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
 */
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary properties) throws ConfigurationException {
    String workflowStatsConfiguration = StringUtils.trimToNull((String) properties.get(STATS_COLLECT_CONFIG_KEY));
    if (StringUtils.isNotEmpty(workflowStatsConfiguration)) {
        try {
            workflowStatsCollect = Boolean.parseBoolean(workflowStatsConfiguration);
            logger.info("Workflow statistics collection is set to %s", workflowStatsConfiguration);
        } catch (Exception e) {
            logger.warn("Workflow statistics collection flag '%s' is malformed, setting to %s", workflowStatsConfiguration, DEFAULT_STATS_COLLECT_CONFIG.toString());
            workflowStatsCollect = DEFAULT_STATS_COLLECT_CONFIG;
        }
    }
}
Also used : Collections.mkString(org.opencastproject.util.data.Collections.mkString) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) UndispatchableJobException(org.opencastproject.serviceregistry.api.UndispatchableJobException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) IOException(java.io.IOException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException)

Aggregations

ConfigurationException (org.osgi.service.cm.ConfigurationException)190 Activate (org.apache.felix.scr.annotations.Activate)31 ServiceReference (org.osgi.framework.ServiceReference)30 Matcher (java.util.regex.Matcher)28 Hashtable (java.util.Hashtable)26 Properties (java.util.Properties)22 IOException (java.io.IOException)21 Test (org.junit.Test)21 ManagedService (org.osgi.service.cm.ManagedService)20 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)19 HashMap (java.util.HashMap)17 File (java.io.File)11 URISyntaxException (java.net.URISyntaxException)11 Collection (java.util.Collection)11 HashSet (java.util.HashSet)11 ServiceTracker (org.osgi.util.tracker.ServiceTracker)10 URI (java.net.URI)9 Dictionary (java.util.Dictionary)9 Map (java.util.Map)9 NotFoundException (org.opencastproject.util.NotFoundException)9