Commit 0d9cb0d9 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

Merge branch '7-event_resource_create-should-be-catched-also-in-service-inventory' into 'develop'

Resolve "EVENT_RESOURCE_CREATE should be catched also in Service inventory"

See merge request !4
parents be4e0cf1 7660bce2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -341,7 +341,7 @@ public class ResourceRepoService {

    boolean resourceStateChanged = false;
    if (resourceUpd.getResourceStatus() != null) {
      if (resourceUpd.getResourceStatus().equals(resource.getResourceStatus())) {
      if (!resourceUpd.getResourceStatus().equals(resource.getResourceStatus())) {
        resourceStateChanged = true;
      }
      resource.setResourceStatus(resourceUpd.getResourceStatus());
+17 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.etsi.osl.tmf.common.model.Notification;
import org.etsi.osl.tmf.ri639.model.ResourceAttributeValueChangeNotification;
import org.etsi.osl.tmf.ri639.model.ResourceCreateNotification;
import org.etsi.osl.tmf.ri639.model.ResourceStateChangeNotification;
import org.etsi.osl.tmf.sim638.model.ServiceActionQueueItem;
import org.etsi.osl.tmf.sim638.model.ServiceCreate;
@@ -93,12 +94,14 @@ public class ServiceApiRouteBuilder extends RouteBuilder {
    @Value("${EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED}")
    private String EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED = "";



    //services care to take this event in case they are related to a specific resource (see CRs)
    @Value("${EVENT_RESOURCE_STATE_CHANGED}")
    private String EVENT_RESOURCE_STATE_CHANGED = "";
    

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

	@Autowired
	private ProducerTemplate template;

@@ -186,12 +189,24 @@ public class ServiceApiRouteBuilder extends RouteBuilder {
		.bean( serviceRepoService, "nfvCatalogNSResourceChanged(${body})");
		
		
		

        from( EVENT_RESOURCE_STATE_CHANGED )
        .log(LoggingLevel.INFO, log, EVENT_RESOURCE_STATE_CHANGED + " message received and will be processed for service inventory!")
        .to("log:DEBUG?showBody=true&showHeaders=true")
        .unmarshal().json( JsonLibrary.Jackson, ResourceStateChangeNotification.class, true)
        .bean( serviceRepoService, "resourceStateChangedEvent(${body})");
        

        from( EVENT_RESOURCE_CREATE )
        .log(LoggingLevel.INFO, log, EVENT_RESOURCE_CREATE + " message received and will be processed for service inventory!")
        .to("log:DEBUG?showBody=true&showHeaders=true")
        .unmarshal().json( JsonLibrary.Jackson, ResourceCreateNotification.class, true)
        .bean( serviceRepoService, "resourceCreatedEvent(${body})");
        
        
        
        
        from( EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED )
        .log(LoggingLevel.INFO, log, EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED + " message received and will be processed for service inventory!")
        .to("log:DEBUG?showBody=true&showHeaders=true")
+71 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import org.etsi.osl.tmf.common.model.service.ServiceStateType;
import org.etsi.osl.tmf.prm669.model.RelatedParty;
import org.etsi.osl.tmf.ri639.model.Resource;
import org.etsi.osl.tmf.ri639.model.ResourceAttributeValueChangeNotification;
import org.etsi.osl.tmf.ri639.model.ResourceCreateNotification;
import org.etsi.osl.tmf.ri639.model.ResourceStateChangeNotification;
import org.etsi.osl.tmf.scm633.reposervices.ServiceSpecificationRepoService;
import org.etsi.osl.tmf.sim638.api.ServiceApiRouteBuilderEvents;
@@ -530,6 +531,12 @@ public class ServiceRepoService {
			service.addNoteItem(noteItem);		
		}
		
		
		
        if (charChangedForNotes.contains( "reconciledAt") ) { //this is just a sync message, so we need to igore such changes
          serviceCharacteristicChanged = false;
        }
		
		if (serviceCharacteristicChanged) {
			Note noteItem = new Note();
			noteItem.setText("Service Characteristic changed: " + charChangedForNotes );
@@ -987,13 +994,76 @@ public class ServiceRepoService {
              this.updateService( aService.getId(), supd , true, null, null); //update the service            
          //}
      }
      
    }
    
    
    @Transactional  
    public void  resourceCreatedEvent(@Valid ResourceCreateNotification resNotif) {
      
      logger.debug("resourceCreatedEvent"); 
      Resource res = resNotif.getEvent().getEvent().getResource();
      logger.info("Will update services related to this resource with id = " + res.getId() );
      
      var aservices = findServicesHavingThisSupportingResourceID(  res.getId() );
      
      for (Service as : aservices) {
        ServiceUpdate supd = new ServiceUpdate();
          
          Service aService = findByUuid(as.getId()); 
          
          //if ( aService.getState().equals( ServiceStateType.ACTIVE )  ) {    
              if ( res.getResourceStatus() != null ) {
                switch (res.getResourceStatus()) {
                  case STANDBY: {
                    supd.setState( ServiceStateType.RESERVED);
                    break;
                  }
                  case SUSPENDED: {
                    supd.setState( ServiceStateType.INACTIVE);
                    break;
                  }
                  case RESERVED: {
                    supd.setState( ServiceStateType.RESERVED);
                    break;
                  }
                  case UNKNOWN: {
                    if (aService.getState().equals( ServiceStateType.ACTIVE  )) {
                      supd.setState( ServiceStateType.TERMINATED);              
                    }
                    break;
                  }
                  case ALARM: {
                    supd.setState( ServiceStateType.INACTIVE);
                    break;
                  }
                  default:
                    break;
                } 
              }
             
              
              Note n = new Note();
              n.setText("Supporting Resource "+ res.getId() + " State Changed with status: " +  res.getResourceStatus());
              n.setAuthor( "SIM638-API" );
              n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() );
              supd.addNoteItem( n );                  
              
              this.updateService( aService.getId(), supd , true, null, null); //update the service            
          //}  //if ( aService.getState().equals( ServiceStateType.ACTIVE )  ) {
      }
      
      
      updateResourceFromKubernetesLabel( res );
      
      
    }
    

    @Transactional  
    public void  resourceStateChangedEvent(@Valid ResourceStateChangeNotification resNotif) {
      
      logger.debug("ResourceAttributeValueChangeNotification"); 
      logger.debug("resourceStateChangedEvent"); 
      Resource res = resNotif.getEvent().getEvent().getResource();
      logger.info("Will update services related to this resource with id = " + res.getId() );