Commit 92d0e31e authored by Christos Tranoris's avatar Christos Tranoris
Browse files

adding a metrico resource spec to osl tmf

parent 9c0ed21a
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -200,7 +200,6 @@
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-api</artifactId>
			<version>5.10.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
+31 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ import org.etsi.osl.tmf.common.model.Any;
import org.etsi.osl.tmf.common.model.service.Characteristic;
import org.etsi.osl.tmf.pm628.model.ExecutionStateType;
import org.etsi.osl.tmf.pm628.model.MeasurementCollectionJob;
import org.etsi.osl.tmf.rcm634.model.LogicalResourceSpecification;
import org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCreate;
import org.etsi.osl.tmf.ri639.model.LogicalResource;
import org.etsi.osl.tmf.ri639.model.Resource;
import org.etsi.osl.tmf.ri639.model.ResourceUpdate;
@@ -55,6 +57,10 @@ public class PrometheusQueries {
    @Value("${CATALOG_UPD_SERVICE}")
    private String CATALOG_UPD_SERVICE = "";
    
    @Value("${CATALOG_UPDADD_RESOURCESPEC}")
    private String CATALOG_UPDADD_RESOURCESPEC = "";
    
    

    @Autowired
    private ProducerTemplate template;
@@ -284,7 +290,31 @@ public class PrometheusQueries {

    
    
    public LogicalResourceSpecification createOrUpdateResourceSpecByNameCategoryVersion( ResourceSpecificationCreate s) {
      logger.info("will createOrUpdateResourceSpecByNameCategoryVersion "  );
      try {
          Map<String, Object> map = new HashMap<>();
          map.put("aname", s.getName());
          map.put("aversion", s.getVersion());
          map.put("acategory", s.getCategory());
          
          Object response = template.requestBodyAndHeaders( CATALOG_UPDADD_RESOURCESPEC, toJsonString(s), map);

          if ( !(response instanceof String)) {
              logger.error("ResourceSpecification  object is wrong.");
          }

          LogicalResourceSpecification rs = toJsonObj( (String)response, LogicalResourceSpecification.class); 
          return rs;
          
          
      }catch (Exception e) {
          logger.error("Cannot create ResourceSpecification");
          e.printStackTrace();
      }
      return null;
      
  }
    
    static <T> T toJsonObj(String content, Class<T> valueType)  throws IOException {
        ObjectMapper mapper = new ObjectMapper();
+42 −0
Original line number Diff line number Diff line
@@ -10,8 +10,11 @@ import org.etsi.osl.metrico.model.Job;
import org.etsi.osl.metrico.prometheus.PrometheusQueries;
import org.etsi.osl.metrico.repo.JobRepository;
import org.etsi.osl.metrico.reposervices.JobRepoService;
import org.etsi.osl.tmf.common.model.ELifecycle;
import org.etsi.osl.tmf.common.model.EValueType;
import org.etsi.osl.tmf.common.model.service.ResourceRef;
import org.etsi.osl.tmf.pm628.model.*;
import org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCreate;
import org.etsi.osl.tmf.ri639.model.LogicalResource;
import org.etsi.osl.tmf.ri639.model.Resource;
import org.etsi.osl.tmf.ri639.model.ResourceUpdate;
@@ -38,6 +41,14 @@ public class MetricoService extends RouteBuilder {

    private static final Logger logger = LoggerFactory.getLogger(JobService.class);


    public static final String OSL_METRICO_RSPEC_NAME = "metrico.osl.etsi.org";
    public static final String OSL_METRICO_RSPEC_VERSION = "0.0.1";
    public static final String OSL_METRICO_RSPEC_CATEGORY = "metrico.osl.etsi.org/v1";
    public static final String OSL_METRICO_RESOURCE_CATEGORY = "metrico.osl.etsi.org/v1";
    public static final String OSL_METRICO_RSPEC_TYPE = "LogicalResourceSpecification";
    public static final String OSL_METRICO_RSPEC_DESCRIPTION = "This Specification is used to describe a generic KubernetesCRD";

    @Value("${PM_MEASUREMENT_COLLECTION_JOB_UPDATE}")
    private String PM_MEASUREMENT_COLLECTION_JOB_UPDATE = "";

@@ -51,6 +62,8 @@ public class MetricoService extends RouteBuilder {
    @Autowired
    private JobRepository jobRepository;
    

    @Autowired
    private final PrometheusQueries prometheusQueries;
    private final ProducerTemplate producerTemplate;

@@ -67,6 +80,8 @@ public class MetricoService extends RouteBuilder {
    @EventListener(ApplicationStartedEvent.class)
    public void onApplicationEvent() {
      
      registerMetricoResourceSpec();
      
      List<Job> jobsPending = jobRepoService.findAll();
      logger.info("===== Pending jobs from previous sessions =====");
      for (Job job : jobsPending) {
@@ -86,6 +101,33 @@ public class MetricoService extends RouteBuilder {
    }


    private void registerMetricoResourceSpec() {
      logger.info("===== Pending jobs from previous sessions =====");
      
      
      ResourceSpecificationCreate rsc = new ResourceSpecificationCreate();
      rsc.setName( "METRICO_RESOURCE_SPECIFICATION" );
      rsc.setCategory( OSL_METRICO_RSPEC_CATEGORY );
      rsc.setVersion( OSL_METRICO_RSPEC_VERSION );
      rsc.setDescription( OSL_METRICO_RSPEC_DESCRIPTION );
      rsc.setType( OSL_METRICO_RSPEC_TYPE );
      
      rsc.setLifecycleStatus( ELifecycle.ACTIVE.getValue() );
      rsc.addResourceSpecificationCharacteristicItemShort( "_MT_CHARACTERISTIC_NAME", "", EValueType.TEXT.getValue(), "Used for providing the characteristic of service _MT_SERVICEUUID to update", false);
      rsc.addResourceSpecificationCharacteristicItemShort( "_MT_SERVICEUUID", "", EValueType.TEXT.getValue(), "Used for providing the id of the service to update", false);
      rsc.addResourceSpecificationCharacteristicItemShort( "_MT_END_TIME", "", EValueType.TEXT.getValue(), "Used for providing the end time", false);
      rsc.addResourceSpecificationCharacteristicItemShort( "_MT_START_TIME", "", EValueType.TEXT.getValue(), "Used for providing start time", false);
      rsc.addResourceSpecificationCharacteristicItemShort( "_MT_RECURRING_INTERVAL", "", EValueType.TEXT.getValue(), "Used for providing the polling interval of prometheus", false);
      rsc.addResourceSpecificationCharacteristicItemShort( "_MT_TYPE", "", EValueType.TEXT.getValue(), "Used for providing ", false);
      rsc.addResourceSpecificationCharacteristicItemShort( "_MT_QUERY", "", EValueType.TEXT.getValue(), "Used for providing the query towards prometheus", false);
      rsc.addResourceSpecificationCharacteristicItemShort( "_MT_URL", "", EValueType.TEXT.getValue(), "Used for providing the prometheus URL", false);
      
      
      prometheusQueries.createOrUpdateResourceSpecByNameCategoryVersion(rsc);
      
    }


    @Autowired
    private ProducerTemplate template;

+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ EVENT_MEASUREMENT_COLLECTION_JOB_EXECUTION_STATE_CHANGED: "jms:topic:EVENT.MEASU
EVENT_MEASUREMENT_COLLECTION_JOB_DELETE:                  "jms:topic:EVENT.MEASUREMENTCOLLECTIONJOB.DELETE"
EVENT_MEASUREMENT_COLLECTION_JOB_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.MEASUREMENTCOLLECTIONJOB.ATTRCHANGED"


CATALOG_UPDADD_RESOURCESPEC: "jms:queue:CATALOG.UPDADD.RESOURCESPEC"
CATALOG_GET_SERVICE_BY_ID: "jms:queue:CATALOG.GET.SERVICE"
CATALOG_GET_RESOURCE_BY_ID: "jms:queue:CATALOG.GET.RESOURCE"
CATALOG_UPD_RESOURCE: "jms:queue:CATALOG.UPD.RESOURCE"
+13 −13
Original line number Diff line number Diff line
@@ -44,17 +44,17 @@ public class MetricoServiceTest {

    }

    @Test
    public void testQueryToPrometheus() {
        String[] result = metricoService.queryToPrometheus(mcj);
        System.out.println(Arrays.toString(result));

        //assertEquals("OK", result);
    }

    @Test
    public void testStartPeriodicQueryToPrometheus() throws InterruptedException {
        metricoService.startPeriodicQueryToPrometheus(mcj);
        Thread.sleep(60000);
    }
//    @Test
//    public void testQueryToPrometheus() {
//        String[] result = metricoService.queryToPrometheus(mcj);
//        System.out.println(Arrays.toString(result));
//
//        //assertEquals("OK", result);
//    }
//
//    @Test
//    public void testStartPeriodicQueryToPrometheus() throws InterruptedException {
//        metricoService.startPeriodicQueryToPrometheus(mcj);
//        Thread.sleep(60000);
//    }
}
 No newline at end of file