Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions features/bsm/rest/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<!-- The shared CXF v2 context instantiates every REST resource; these
provide the topology-assets service's model + jsonStore bean, which
webapp-rest declares as provided (non-transitive). -->
<dependency>
<groupId>org.opennms</groupId>
<artifactId>org.opennms.features.topology-assets</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opennms.features.distributed</groupId>
<artifactId>org.opennms.features.distributed.kv-store.json.postgres</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opennms.dependencies</groupId>
<artifactId>cxf-dependencies</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions features/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<!-- Topologies -->
<module>topologies</module>

<!-- Topology view image assets (backgrounds, custom node icons) -->
<module>topology-assets</module>

<!-- ActiveMQ broker -->
<module>activemq</module>

Expand Down
15 changes: 15 additions & 0 deletions features/status/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!-- The shared CXF v2 context instantiates every REST resource; these
provide the topology-assets service's model + jsonStore bean, which
webapp-rest declares as provided (non-transitive). -->
<dependency>
<groupId>org.opennms</groupId>
<artifactId>org.opennms.features.topology-assets</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opennms.features.distributed</groupId>
<artifactId>org.opennms.features.distributed.kv-store.json.postgres</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opennms.features.bsm</groupId>
<artifactId>org.opennms.features.bsm.service.impl</artifactId>
Expand Down
105 changes: 105 additions & 0 deletions features/topology-assets/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.opennms</groupId>
<artifactId>org.opennms.features</artifactId>
<version>36.0.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.opennms.features.topology-assets</artifactId>
<packaging>bundle</packaging>
<name>OpenNMS :: Features :: Topology Assets</name>
<description>
Storage for images referenced by custom topology views: background
images (floor plans, rack diagrams) and custom node icons. Bytes are
kept in the generic binary key-value store and the catalog metadata
in the JSON key-value store; this module owns the model and DAO. The
JAX-RS resource that exposes /api/v2/topology/assets lives in
opennms-webapp-rest.
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-RequiredExecutionEnvironment>JavaSE-1.8</Bundle-RequiredExecutionEnvironment>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.opennms.dependencies</groupId>
<artifactId>spring-dependencies</artifactId>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.opennms.features.distributed</groupId>
<artifactId>org.opennms.features.distributed.kv-store.api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<!-- The Postgres-backed BlobStore for the image bytes. Not in the default
runtime lib (only the no-op is), so this is a compile dependency and
the jar is added to opennms-base-assembly alongside this module. -->
<dependency>
<groupId>org.opennms.features.distributed</groupId>
<artifactId>org.opennms.features.distributed.kv-store.blob.postgres</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gsonVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opennms.core.test-api</groupId>
<artifactId>org.opennms.core.test-api.lib</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opennms.core.test-api</groupId>
<artifactId>org.opennms.core.test-api.db</artifactId>
<scope>test</scope>
</dependency>
<!-- PostgresJsonStore + its spring context for the DAO integration test. -->
<dependency>
<groupId>org.opennms.features.distributed</groupId>
<artifactId>org.opennms.features.distributed.kv-store.json.postgres</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Licensed to The OpenNMS Group, Inc (TOG) under one or more
* contributor license agreements. See the LICENSE.md file
* distributed with this work for additional information
* regarding copyright ownership.
*
* TOG licenses this file to You under the GNU Affero General
* Public License Version 3 (the "License") or (at your option)
* any later version. You may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at:
*
* https://www.gnu.org/licenses/agpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.opennms.netmgt.topology.assets;

import java.util.Date;

import com.google.common.base.MoreObjects;

/**
* Catalog metadata for an image used by custom topology views: a background
* (floor plan, rack diagram) or a custom node icon.
*
* <p>This is the metadata only — the image bytes are stored separately in the
* binary key-value store and served by id (see {@code TopologyAssetKvStore}).
* Views reference an asset by its {@link #getId() id} from their (opaque)
* definition document, e.g. a background's {@code ref} or a node's icon.
*
* <p>{@link #getKind() kind} distinguishes the intended use
* ({@code background} vs {@code icon}) so pickers can list only what fits and
* the upload path can apply a size limit appropriate to each. Assets are a
* shared catalog like the views themselves; {@link #getOwner() owner} records
* who uploaded it (informational).
*/
public class TopologyAsset {

public static final String KIND_BACKGROUND = "background";
public static final String KIND_ICON = "icon";

private String id;
private String name;
private String kind;
private String mimeType;
private long sizeBytes;
private String owner;
private Date created;
private Date lastModified;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getKind() {
return kind;
}

public void setKind(String kind) {
this.kind = kind;
}

public String getMimeType() {
return mimeType;
}

public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}

public long getSizeBytes() {
return sizeBytes;
}

public void setSizeBytes(long sizeBytes) {
this.sizeBytes = sizeBytes;
}

public String getOwner() {
return owner;
}

public void setOwner(String owner) {
this.owner = owner;
}

public Date getCreated() {
return created;
}

public void setCreated(Date created) {
this.created = created;
}

public Date getLastModified() {
return lastModified;
}

public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.add("name", name)
.add("kind", kind)
.add("mimeType", mimeType)
.add("sizeBytes", sizeBytes)
.add("owner", owner)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to The OpenNMS Group, Inc (TOG) under one or more
* contributor license agreements. See the LICENSE.md file
* distributed with this work for additional information
* regarding copyright ownership.
*
* TOG licenses this file to You under the GNU Affero General
* Public License Version 3 (the "License") or (at your option)
* any later version. You may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at:
*
* https://www.gnu.org/licenses/agpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.opennms.netmgt.topology.assets;

import java.util.List;
import java.util.Optional;

/**
* Access to the shared catalog of topology image assets (backgrounds and
* custom node icons). Metadata and bytes are stored and fetched separately so
* listings never drag image payloads along.
*
* <p>Validation (allowed MIME types, size limits per kind) is the caller's
* concern — the REST layer enforces it; this store is format-agnostic.
*/
public interface TopologyAssetDao {

/**
* Stores a new asset. The id, byte size, and timestamps are assigned here;
* everything else (name, kind, MIME type, owner) comes filled in on
* {@code asset}.
*
* @return the stored metadata, with the generated id set.
*/
TopologyAsset save(TopologyAsset asset, byte[] bytes);

/** The metadata for an asset, if it exists. */
Optional<TopologyAsset> get(String id);

/** The image bytes for an asset, if it exists. */
Optional<byte[]> getBytes(String id);

/** All assets' metadata (never the bytes). */
List<TopologyAsset> findAll();

/**
* Removes an asset (metadata and bytes).
*
* @return whether an asset with that id existed.
*/
boolean delete(String id);
}
Loading
Loading