diff --git a/features/mib-compiler/rest/pom.xml b/features/mib-compiler/rest/pom.xml
index 45db9f4b6898..099624b91e79 100644
--- a/features/mib-compiler/rest/pom.xml
+++ b/features/mib-compiler/rest/pom.xml
@@ -49,7 +49,27 @@
${project.version}
provided
+
+ org.opennms
+ opennms-dao
+ provided
+
+
+ org.opennms.core.test-api
+ org.opennms.core.test-api.lib
+ test
+
+
+ org.opennms.core.test-api
+ org.opennms.core.test-api.db
+ test
+
+
+ org.opennms.core.test-api
+ org.opennms.core.test-api.services
+ test
+
junit
junit
diff --git a/features/mib-compiler/rest/src/main/java/org/opennms/features/mibcompiler/rest/MibCompilerRestService.java b/features/mib-compiler/rest/src/main/java/org/opennms/features/mibcompiler/rest/MibCompilerRestService.java
index e17ee1646804..5e2ff4bab43d 100644
--- a/features/mib-compiler/rest/src/main/java/org/opennms/features/mibcompiler/rest/MibCompilerRestService.java
+++ b/features/mib-compiler/rest/src/main/java/org/opennms/features/mibcompiler/rest/MibCompilerRestService.java
@@ -21,11 +21,16 @@
*/
package org.opennms.features.mibcompiler.rest;
+import org.opennms.features.mibcompiler.rest.model.MibCompilerGenerateEventsRequest;
+
+import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.DELETE;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -36,10 +41,45 @@ public interface MibCompilerRestService {
@POST
@Path("/upload")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
- Response uploadMib(byte[] mibContent, @QueryParam("filename") String filename);
+ @Produces(MediaType.APPLICATION_JSON)
+ Response uploadMib(byte[] mibContent, @QueryParam("filename") String filename) throws Exception;
@POST
@Path("/compile")
@Consumes(MediaType.APPLICATION_JSON)
- Response compileMib(@QueryParam("name") String name);
+ @Produces(MediaType.APPLICATION_JSON)
+ Response compileMib(@QueryParam("name") String name) throws Exception;
+
+ @GET
+ @Path("/files")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ Response listPendingAndCompiledFiles() throws Exception;
+
+ @DELETE
+ @Path("/files/{location}/{fileName:.+}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ Response deleteFile(@PathParam("location") String location,
+ @PathParam("fileName") String fileName) throws Exception;
+
+ @GET
+ @Path("/files/{location}/{fileName:.+}/text")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ Response getFileText(@PathParam("location") String location,
+ @PathParam("fileName") String fileName) throws Exception;
+
+ @POST
+ @Path("/files/pending/text")
+ @Consumes(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.APPLICATION_JSON)
+ Response setFileText(@QueryParam("fileName") String fileName,
+ byte[] mibContent) throws Exception;
+
+ @POST
+ @Path("/generate-events")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ Response generateEvents(MibCompilerGenerateEventsRequest request) throws Exception;
}
diff --git a/features/mib-compiler/rest/src/main/java/org/opennms/features/mibcompiler/rest/internal/MibCompilerRestServiceImpl.java b/features/mib-compiler/rest/src/main/java/org/opennms/features/mibcompiler/rest/internal/MibCompilerRestServiceImpl.java
index b28234647e9e..0744bb7428b0 100644
--- a/features/mib-compiler/rest/src/main/java/org/opennms/features/mibcompiler/rest/internal/MibCompilerRestServiceImpl.java
+++ b/features/mib-compiler/rest/src/main/java/org/opennms/features/mibcompiler/rest/internal/MibCompilerRestServiceImpl.java
@@ -21,36 +21,568 @@
*/
package org.opennms.features.mibcompiler.rest.internal;
+import org.apache.commons.lang.StringUtils;
import org.opennms.features.mibcompiler.api.MibParser;
import org.opennms.features.mibcompiler.rest.MibCompilerRestService;
+import org.opennms.features.mibcompiler.rest.model.MibCompilerFileText;
+import org.opennms.features.mibcompiler.rest.model.MibCompilerGenerateEventsRequest;
+import org.opennms.netmgt.config.api.EventConfDao;
+import org.opennms.netmgt.dao.api.EventConfEventDao;
+import org.opennms.netmgt.dao.api.EventConfSourceDao;
+import org.opennms.netmgt.dao.support.EventConfServiceHelper;
+import org.opennms.netmgt.model.EventConfSource;
+import org.opennms.netmgt.model.events.EventConfSourceMetadataDto;
+import org.opennms.netmgt.xml.eventconf.Events;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.transaction.support.TransactionOperations;
+import javax.annotation.PreDestroy;
import javax.ws.rs.core.Response;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.List;
+import java.util.LinkedHashMap;
+import java.util.Date;
+import java.util.Optional;
+import java.util.concurrent.ExecutorService;
public class MibCompilerRestServiceImpl implements MibCompilerRestService {
private static final Logger LOG = LoggerFactory.getLogger(MibCompilerRestServiceImpl.class);
+ private static final String UNKNOWN_FILENAME = "unknown";
+ private static final int MAX_FILENAME_LENGTH = 255;
+
private final MibParser mibParser;
+ private final EventConfSourceDao eventConfSourceDao;
+ private final EventConfEventDao eventConfEventDao;
+ private final EventConfDao eventConfDao;
+ private final TransactionOperations operations;
+
+ private final ExecutorService eventConfExecutor =
+ EventConfServiceHelper.createEventConfExecutor("load-eventConf-%d");
- public MibCompilerRestServiceImpl(MibParser mibParser) {
- this.mibParser = mibParser;
+ public MibCompilerRestServiceImpl(
+ final MibParser mibParser, EventConfSourceDao eventConfSourceDao, EventConfEventDao eventConfEventDao, EventConfDao eventConfDao, TransactionOperations operations) {
+ this.mibParser = Objects.requireNonNull(mibParser, "mibParser must not be null");
+ this.eventConfSourceDao = eventConfSourceDao;
+ this.eventConfEventDao = eventConfEventDao;
+ this.eventConfDao = eventConfDao;
+ this.operations = operations;
+
+ this.mibParser.setMibDirectory(MibCompilerServiceUtil.getCompiledDir());
}
@Override
- public Response uploadMib(byte[] mibContent, String filename) {
- // TODO: implement MIB upload to pending directory
- return Response.status(Response.Status.SERVICE_UNAVAILABLE)
- .entity("{\"error\": \"Not yet implemented\"}")
- .build();
+ public Response uploadMib(final byte[] mibContent, final String filename) throws Exception {
+ final List