Exemple #1
0
def update_browse_layer(browse_layer, config=None):
    config = config or get_ngeo_config()

    try:
        browse_layer_model = models.BrowseLayer.objects.get(id=browse_layer.id)
    except models.BrowseLayer.DoesNotExist:
        raise Exception("Could not update the previous browse layer")

    immutable_values = (
        "id", "browse_type", "contains_vertical_curtains", "r_band", "g_band",
        "b_band", "radiometric_interval_min", "radiometric_interval_max",
        "grid", "lowest_map_level", "highest_map_level", "strategy"
    )
    for key in immutable_values:
        if getattr(browse_layer_model, key) != getattr(browse_layer, key):
            raise Exception("Cannot change immutable property '%s'." % key)

    mutable_values = [
        "title", "description", "browse_access_policy",
        "timedimension_default", "tile_query_limit"
    ]

    refresh_mapcache_xml = False
    for key in mutable_values:
        setattr(browse_layer_model, key, getattr(browse_layer, key))
        if key in ("timedimension_default", "tile_query_limit"):
            refresh_mapcache_xml = True

    for related_dataset_id in browse_layer.related_dataset_ids:
        models.RelatedDataset.objects.get_or_create(
            dataset_id=related_dataset_id, browse_layer=browse_layer_model
        )

    # remove all related datasets that are not referenced anymore
    models.RelatedDataset.objects.filter(
        browse_layer=browse_layer_model
    ).exclude(
        dataset_id__in=browse_layer.related_dataset_ids
    ).delete()

    browse_layer_model.full_clean()
    browse_layer_model.save()

    if not browse_layer.contains_volumes and not browse_layer.contains_vertical_curtains:
        if refresh_mapcache_xml:
            remove_mapcache_layer_xml(browse_layer, config)
            add_mapcache_layer_xml(browse_layer, config)
Exemple #2
0
def delete_browse_layer(browse_layer, config=None):
    config = config or get_ngeo_config()

    # remove browse layer model. This should also delete all related browses
    # and browse reports
    models.BrowseLayer.objects.get(id=browse_layer.id).delete()
    eoxs_models.DatasetSeries.objects.get(identifier=browse_layer.id).delete()

    if not browse_layer.contains_volumes and not browse_layer.contains_vertical_curtains:
        # remove source from mapcache sqlite
        mapcache_models.Source.objects.get(name=browse_layer.id).delete()

        # remove browse layer from mapcache XML
        remove_mapcache_layer_xml(browse_layer, config)

        # delete browse layer cache
        try:
            os.remove(get_tileset_path(browse_layer.browse_type))
        except OSError:
            # when no browse was ingested, the sqlite file does not exist, so just
            # issue a warning
            logger.warning(
                "Could not remove tileset '%s'." 
                % get_tileset_path(browse_layer.browse_type)
            )

    # delete all optimzed files by deleting the whole directory of the layer
    optimized_dir = get_project_relative_path(join(
        config.get(INGEST_SECTION, "optimized_files_dir"), browse_layer.id
    ))
    try:
        shutil.rmtree(optimized_dir)
    except OSError:
        logger.error(
            "Could not remove directory for optimzed files: '%s'." 
            % optimized_dir
        )
Exemple #3
0
def delete_browse_layer(browse_layer, purge=False, config=None):
    config = config or get_ngeo_config()

    # only remove MapCache configuration in order to allow a roll-back
    # without data loss
    if models.BrowseLayer.objects.filter(id=browse_layer.id).exists():
        logger.info("Starting disabling of browse layer '%s'." % browse_layer.id)
    else:
        raise Exception(
            "Could not disable browse layer '%s' as it does not exist."
            % browse_layer.id
        )

    # remove browse layer from MapCache XML
    remove_mapcache_layer_xml(browse_layer, config)

    logger.info("Finished disabling of browse layer '%s'." % browse_layer.id)

    if purge:
        logger.info("Starting purging of browse layer '%s'." % browse_layer.id)
        # remove browse layer model. This should also delete all related browses
        # and browse reports
        models.BrowseLayer.objects.get(id=browse_layer.id).delete()

        # delete EOxServer layer metadata
        dss = System.getRegistry().getFromFactory(
            "resources.coverages.wrappers.DatasetSeriesFactory",
            {"obj_id": browse_layer.id}
        )
        dss._DatasetSeriesWrapper__model.layer_metadata.all().delete()
        # delete EOxServer dataset series
        dss_mgr = System.getRegistry().findAndBind(
            intf_id="resources.coverages.interfaces.Manager",
            params={
                "resources.coverages.interfaces.res_type": "eo.dataset_series"
            }
        )
        dss_mgr.delete(browse_layer.id)

        # remove source from mapcache sqlite
        mapcache_models.Source.objects.get(name=browse_layer.id).delete()

        # delete browse layer cache
        try:
            logger.info(
                "Deleting tileset for browse layer '%s'." % browse_layer.id
            )
            os.remove(get_tileset_path(browse_layer.browse_type))
        except OSError:
            # when no browse was ingested, the sqlite file does not exist, so
            # just issue a warning
            logger.warning(
                "Could not remove tileset '%s'."
                % get_tileset_path(browse_layer.browse_type)
            )

        # delete all optimized files by deleting the whole directory of the layer
        optimized_dir = get_project_relative_path(join(
            config.get(INGEST_SECTION, "optimized_files_dir"), browse_layer.id
        ))
        try:
            logger.info(
                "Deleting optimized images for browse layer '%s'."
                % browse_layer.id
            )
            shutil.rmtree(optimized_dir)
        except OSError:
            logger.error(
                "Could not remove directory for optimized files: '%s'."
                % optimized_dir
            )

        logger.info("Finished purging of browse layer '%s'." % browse_layer.id)
Exemple #4
0
def update_browse_layer(browse_layer, config=None):
    config = config or get_ngeo_config()

    try:
        logger.info("Fetching browse layer '%s' for update." % browse_layer.id)
        browse_layer_model = models.BrowseLayer.objects.get(id=browse_layer.id)
    except models.BrowseLayer.DoesNotExist:
        raise Exception(
            "Could not update browse layer '%s' as it does not exist."
            % browse_layer.id
        )

    immutable_values = (
        "id", "browse_type", "contains_vertical_curtains", "r_band", "g_band",
        "b_band", "radiometric_interval_min", "radiometric_interval_max",
        "grid", "lowest_map_level", "highest_map_level"
    )
    for key in immutable_values:
        if getattr(browse_layer_model, key) != getattr(browse_layer, key):
            raise Exception("Cannot change immutable property '%s'." % key)

    mutable_values = [
        "title", "description", "browse_access_policy",
        "timedimension_default", "tile_query_limit", "strategy"
    ]

    refresh_mapcache_xml = False
    refresh_metadata = False
    for key in mutable_values:
        setattr(browse_layer_model, key, getattr(browse_layer, key))
        if key in ("timedimension_default", "tile_query_limit"):
            refresh_mapcache_xml = True
        if key in ("title", "description"):
            refresh_metadata = True

    # relatedDatasets are ignored (see NGEO-1508)
    # for related_dataset_id in browse_layer.related_dataset_ids:
    #     models.RelatedDataset.objects.get_or_create(
    #         dataset_id=related_dataset_id, browse_layer=browse_layer_model
    #     )

    # # remove all related datasets that are not referenced any more
    # models.RelatedDataset.objects.filter(
    #     browse_layer=browse_layer_model
    # ).exclude(
    #     dataset_id__in=browse_layer.related_dataset_ids
    # ).delete()

    browse_layer_model.full_clean()
    browse_layer_model.save()

    # update EOxServer layer metadata
    if refresh_metadata:
        dss = System.getRegistry().getFromFactory(
            "resources.coverages.wrappers.DatasetSeriesFactory",
            {"obj_id": browse_layer.id}
        )
        dss._DatasetSeriesWrapper__model.layer_metadata.all().delete()
        if browse_layer.title:
            md_title = LayerMetadataRecord.objects.get_or_create(
                key="ows_title", value=str(browse_layer.title))[0]
            dss._DatasetSeriesWrapper__model.layer_metadata.add(md_title)
        if browse_layer.description:
            md_abstract = LayerMetadataRecord.objects.get_or_create(
                key="ows_abstract", value=str(browse_layer.description))[0]
            dss._DatasetSeriesWrapper__model.layer_metadata.add(md_abstract)

    if refresh_mapcache_xml:
        try:
            remove_mapcache_layer_xml(browse_layer, config)
        except LayerException:
            logger.info("Nothing to be removed. Layer disabled?")
        add_mapcache_layer_xml(browse_layer, config)
    logger.info("Finished updating browse layer '%s'." % browse_layer.id)
Exemple #5
0
def delete_browse_layer(browse_layer, purge=False, config=None):
    config = config or get_ngeo_config()

    # only remove MapCache configuration in order to allow a roll-back
    # without data loss
    if models.BrowseLayer.objects.filter(id=browse_layer.id).exists():
        logger.info("Starting disabling of browse layer '%s'." %
                    browse_layer.id)
    else:
        raise Exception(
            "Could not disable browse layer '%s' as it does not exist." %
            browse_layer.id)

    # remove browse layer from MapCache XML
    remove_mapcache_layer_xml(browse_layer, config)

    # disable SxCat harvesting for collection
    harvesting_via_sxcat = False
    try:
        harvesting_via_sxcat = config.getboolean("control",
                                                 "harvesting_via_sxcat")
    except:
        pass
    if harvesting_via_sxcat and browse_layer.harvesting_source:
        disable_collection(browse_layer)

    logger.info("Finished disabling of browse layer '%s'." % browse_layer.id)

    if purge:
        logger.info("Starting purging of browse layer '%s'." % browse_layer.id)
        # remove browse layer model. This should also delete all related browses
        # and browse reports
        models.BrowseLayer.objects.get(id=browse_layer.id).delete()

        # delete EOxServer layer metadata
        dss = System.getRegistry().getFromFactory(
            "resources.coverages.wrappers.DatasetSeriesFactory",
            {"obj_id": browse_layer.id})
        dss._DatasetSeriesWrapper__model.layer_metadata.all().delete()
        # delete EOxServer dataset series
        dss_mgr = System.getRegistry().findAndBind(
            intf_id="resources.coverages.interfaces.Manager",
            params={
                "resources.coverages.interfaces.res_type": "eo.dataset_series"
            })
        dss_mgr.delete(browse_layer.id)

        # remove source from mapcache sqlite
        mapcache_models.Source.objects.get(name=browse_layer.id).delete()

        # delete browse layer cache
        try:
            logger.info("Deleting tileset for browse layer '%s'." %
                        browse_layer.id)
            os.remove(get_tileset_path(browse_layer.browse_type))
        except OSError:
            # when no browse was ingested, the sqlite file does not exist, so
            # just issue a warning
            logger.warning("Could not remove tileset '%s'." %
                           get_tileset_path(browse_layer.browse_type))

        # delete all optimized files by deleting the whole directory of the layer
        optimized_dir = get_project_relative_path(
            join(config.get(INGEST_SECTION, "optimized_files_dir"),
                 browse_layer.id))
        try:
            logger.info("Deleting optimized images for browse layer '%s'." %
                        browse_layer.id)
            shutil.rmtree(optimized_dir)
        except OSError:
            logger.error(
                "Could not remove directory for optimized files: '%s'." %
                optimized_dir)

        if harvesting_via_sxcat and browse_layer.harvesting_source:
            remove_collection(browse_layer)

        logger.info("Finished purging of browse layer '%s'." % browse_layer.id)
Exemple #6
0
def update_browse_layer(browse_layer, config=None):
    config = config or get_ngeo_config()

    try:
        logger.info("Fetching browse layer '%s' for update." % browse_layer.id)
        browse_layer_model = models.BrowseLayer.objects.get(id=browse_layer.id)
    except models.BrowseLayer.DoesNotExist:
        raise Exception(
            "Could not update browse layer '%s' as it does not exist." %
            browse_layer.id)

    immutable_values = ("id", "browse_type", "contains_vertical_curtains",
                        "r_band", "g_band", "b_band",
                        "radiometric_interval_min", "radiometric_interval_max",
                        "grid", "lowest_map_level", "highest_map_level",
                        "harvesting_source")
    for key in immutable_values:
        if getattr(browse_layer_model, key) != getattr(browse_layer, key):
            raise Exception("Cannot change immutable property '%s'." % key)

    mutable_values = [
        "title", "description", "browse_access_policy",
        "timedimension_default", "tile_query_limit", "strategy"
    ]

    refresh_mapcache_xml = False
    refresh_metadata = False
    for key in mutable_values:
        setattr(browse_layer_model, key, getattr(browse_layer, key))
        if key in ("timedimension_default", "tile_query_limit"):
            refresh_mapcache_xml = True
        if key in ("title", "description"):
            refresh_metadata = True

    # relatedDatasets are ignored (see NGEO-1508)
    # for related_dataset_id in browse_layer.related_dataset_ids:
    #     models.RelatedDataset.objects.get_or_create(
    #         dataset_id=related_dataset_id, browse_layer=browse_layer_model
    #     )

    # # remove all related datasets that are not referenced any more
    # models.RelatedDataset.objects.filter(
    #     browse_layer=browse_layer_model
    # ).exclude(
    #     dataset_id__in=browse_layer.related_dataset_ids
    # ).delete()

    browse_layer_model.full_clean()
    browse_layer_model.save()

    # update EOxServer layer metadata
    if refresh_metadata:
        dss = System.getRegistry().getFromFactory(
            "resources.coverages.wrappers.DatasetSeriesFactory",
            {"obj_id": browse_layer.id})
        dss._DatasetSeriesWrapper__model.layer_metadata.all().delete()
        if browse_layer.title:
            md_title = LayerMetadataRecord.objects.get_or_create(
                key="ows_title", value=str(browse_layer.title))[0]
            dss._DatasetSeriesWrapper__model.layer_metadata.add(md_title)
        if browse_layer.description:
            md_abstract = LayerMetadataRecord.objects.get_or_create(
                key="ows_abstract", value=str(browse_layer.description))[0]
            dss._DatasetSeriesWrapper__model.layer_metadata.add(md_abstract)

    if refresh_mapcache_xml:
        try:
            remove_mapcache_layer_xml(browse_layer, config)
        except LayerException:
            logger.info("Nothing to be removed. Layer disabled?")
        add_mapcache_layer_xml(browse_layer, config)

    # re-configure SxCat harvesting for collection
    harvesting_via_sxcat = False
    try:
        harvesting_via_sxcat = config.getboolean("control",
                                                 "harvesting_via_sxcat")
    except:
        pass
    if (harvesting_via_sxcat and browse_layer.harvesting_source
            and browse_layer.harvesting_source
            == browse_layer_model.harvesting_source):
        add_collection(browse_layer)

    logger.info("Finished updating browse layer '%s'." % browse_layer.id)