Search in sources :

Example 1 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class OwsServiceIdentificationFactory method setAbstract.

@Setting(OwsServiceIdentificationFactorySettings.ABSTRACT)
public void setAbstract(Object description) throws ConfigurationError {
    Validation.notNull("Service Identification Abstract", description);
    if (description instanceof MultilingualString) {
        this.abstrakt = (MultilingualString) description;
    } else if (description instanceof String) {
        this.abstrakt = createFromString(description);
    } else {
        throw new ConfigurationError(String.format("%s is not supported as abstract!", description.getClass().getName()));
    }
    setRecreate();
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) MultilingualString(org.n52.janmayen.i18n.MultilingualString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) Setting(org.n52.faroe.annotation.Setting)

Example 2 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class OwsServiceIdentificationFactory method setTitle.

@Setting(OwsServiceIdentificationFactorySettings.TITLE)
public void setTitle(Object title) throws ConfigurationError {
    Validation.notNull("Service Identification Title", title);
    if (title instanceof MultilingualString) {
        this.title = (MultilingualString) title;
    } else if (title instanceof String) {
        this.title = createFromString(title);
    } else {
        throw new ConfigurationError(String.format("%s is not supported as title!", title.getClass().getName()));
    }
    setRecreate();
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) MultilingualString(org.n52.janmayen.i18n.MultilingualString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) Setting(org.n52.faroe.annotation.Setting)

Example 3 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class ElasticsearchAdminHandler method addUuidToMetadataIfNeeded.

@SuppressWarnings("unchecked")
private void addUuidToMetadataIfNeeded(String uuid) throws ElasticsearchException {
    GetResponse resp = client.prepareGet(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setOperationThreaded(false).get();
    Object retValues = resp.getSourceAsMap().get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName());
    List<String> values;
    if (retValues instanceof String) {
        values = new LinkedList<>();
        values.add((String) retValues);
    } else if (retValues instanceof List<?>) {
        values = (List<String>) retValues;
    } else {
        throw new ConfigurationError("Invalid %s field type %s should have String or java.util.Collection<String>", MetadataDataMapping.METADATA_UUIDS_FIELD, retValues.getClass());
    }
    // add new uuid if needed
    if (!values.stream().anyMatch(m -> m.equals(uuid))) {
        Map<String, Object> uuids = new HashMap<>();
        values.add(uuid);
        uuids.put(MetadataDataMapping.METADATA_UUIDS_FIELD.getName(), values);
        uuids.put(MetadataDataMapping.METADATA_UPDATE_TIME_FIELD.getName(), Calendar.getInstance(DateTimeZone.UTC.toTimeZone()));
        client.prepareUpdate(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, "1").setDoc(uuids).get();
        logger.info("UUID {} is added to the {} type", uuid, MetadataDataMapping.METADATA_TYPE_NAME);
    }
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) ElasticsearchException(org.elasticsearch.ElasticsearchException) GetResponse(org.elasticsearch.action.get.GetResponse) DateTimeZone(org.joda.time.DateTimeZone) ConfigurationError(org.n52.faroe.ConfigurationError) KibanaImporter(org.n52.iceland.statistics.api.utils.KibanaImporter) NodeBuilder(org.elasticsearch.node.NodeBuilder) TransportClient(org.elasticsearch.client.transport.TransportClient) LoggerFactory(org.slf4j.LoggerFactory) MetadataDataMapping(org.n52.iceland.statistics.api.mappings.MetadataDataMapping) HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) Inject(javax.inject.Inject) Calendar(java.util.Calendar) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) EmbeddedElasticsearch(org.n52.iceland.statistics.impl.server.EmbeddedElasticsearch) Node(org.elasticsearch.node.Node) ElasticsearchSettings(org.n52.iceland.statistics.api.ElasticsearchSettings) ElasticsearchSettingsKeys(org.n52.iceland.statistics.api.ElasticsearchSettingsKeys) LinkedList(java.util.LinkedList) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Logger(org.slf4j.Logger) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) UnknownHostException(java.net.UnknownHostException) StandardCharsets(java.nio.charset.StandardCharsets) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ServletContext(javax.servlet.ServletContext) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IAdminDataHandler(org.n52.iceland.statistics.api.interfaces.datahandler.IAdminDataHandler) DefaultElasticsearchSchemas(org.n52.iceland.statistics.impl.schemabuilders.DefaultElasticsearchSchemas) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) List(java.util.List) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 4 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class ElasticsearchAdminHandler method createSchema.

@Override
public synchronized void createSchema() {
    IndicesAdminClient indices = client.admin().indices();
    if (indices.prepareExists(settings.getIndexId()).get().isExists()) {
        logger.info("Index {} already exists", settings.getIndexId());
        // update mapping
        Integer version = getCurrentVersion();
        logger.info("Elasticsearch schema version is {}", version);
        if (version == null) {
            throw new ConfigurationError("Database inconsistency. Metadata version not found in type %s", MetadataDataMapping.METADATA_TYPE_NAME);
        }
        if (version != schemas.getSchemaVersion()) {
            throw new ConfigurationError("Database schema version inconsistency. Version numbers don't match. " + "Database version number %d <-> Application version number %d", version, schemas.getSchemaVersion());
        }
        addUuidToMetadataIfNeeded(settings.getUuid());
    } else {
        logger.info("Index {} not exists creating a new one now.", settings.getIndexId());
        // create metadata table and index table table
        CreateIndexResponse response = indices.prepareCreate(settings.getIndexId()).addMapping(MetadataDataMapping.METADATA_TYPE_NAME, schemas.getMetadataSchema()).addMapping(settings.getTypeId(), schemas.getSchema()).get();
        logger.debug("Created indices: {}", response);
        // insert metadata values
        createMetadataType(schemas.getSchemaVersion());
    }
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Example 5 with ConfigurationError

use of org.n52.faroe.ConfigurationError in project arctic-sea by 52North.

the class AbstractPropertyFileHandler method save.

public void save(String m, String value) throws ConfigurationError {
    lock.writeLock().lock();
    try {
        Properties p = load();
        p.setProperty(m, value);
        save(p);
    } catch (IOException e) {
        throw new ConfigurationError(ERROR_WRITING_MESSAGE, e);
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) IOException(java.io.IOException) Properties(java.util.Properties)

Aggregations

ConfigurationError (org.n52.faroe.ConfigurationError)7 IOException (java.io.IOException)4 Properties (java.util.Properties)3 Setting (org.n52.faroe.annotation.Setting)3 MultilingualString (org.n52.janmayen.i18n.MultilingualString)3 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)2 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Joiner (com.google.common.base.Joiner)1 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1