Commit f5c57ed4 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

Merge branch '38-adding-declareresourcestatus-in-resourceupdate' into...

Merge branch '38-adding-declareresourcestatus-in-resourceupdate' into 39-fix-serviceorderitem-and-productorderitem-findorderitembyid-null-throws
parents e3c8b2ee a4642130
Loading
Loading
Loading
Loading
Loading
+5
Changes for pom.xml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -113,6 +113,11 @@
			<version>13.0</version>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	
		<build>
+17
Changes for src/main/java/org/etsi/osl/tmf/rcm634/model/ResourceSpecification.java: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -24,7 +24,10 @@ import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.etsi.osl.tmf.common.model.AttachmentRefOrValue;
import org.etsi.osl.tmf.common.model.BaseEntity;
import org.etsi.osl.tmf.prm669.model.RelatedParty;
@@ -53,6 +56,20 @@ import jakarta.validation.Valid;
@Schema(description = "Resources are physical or non-physical components (or some combination of these) within an enterprise's infrastructure or inventory. They are typically consumed or used by services (for example a physical port assigned to a service) or contribute to the realization of a Product (for example, a SIM card). They can be drawn from the Application, Computing and Network domains, and include, for example, Network Elements, software, IT systems, content and information, and technology components. A ResourceSpecification is an abstract base class for representing a generic means for implementing a particular type of Resource. In essence, a ResourceSpecification defines the common attributes and relationships of a set of related Resources, while Resource defines a specific instance that is based on a particular ResourceSpecification.")
@Validated
@jakarta.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2021-05-29T22:34:44.143740800+03:00[Europe/Athens]")
@JsonIgnoreProperties(
		value = "@type", // ignore manually set @type, it will be automatically generated by Jackson during serialization
		allowSetters = true // allows the @type to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type",
		visible = true, defaultImpl = LogicalResourceSpecification.class)
@JsonSubTypes({
		@JsonSubTypes.Type(value = LogicalResourceSpecification.class, name = "LogicalResourceSpecification"),
		@JsonSubTypes.Type(value = PhysicalResourceSpecification.class, name = "PhysicalResourceSpecification"),
		// Extends LogicalResourceSpecification and adds its own fields, so it must be listed too:
		// without it a ResourceFunctionSpecification payload falls back to the defaultImpl and then
		// fails on connectionPointSpecification / connectivitySpecification.
		@JsonSubTypes.Type(value = ResourceFunctionSpecification.class, name = "ResourceFunctionSpecification")
})
@Entity(name = "ResSpec")
public abstract class ResourceSpecification extends BaseEntity {
	@JsonProperty("id")
+84
Changes for src/main/java/org/etsi/osl/tmf/ri639/model/Resource.java: 84 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
import org.etsi.osl.tmf.common.model.AttachmentRefOrValue;
import org.etsi.osl.tmf.common.model.BaseRootNamedEntity;
import org.etsi.osl.tmf.common.model.service.Note;
@@ -30,6 +32,17 @@ import jakarta.validation.constraints.NotNull;
@Schema(description = "Resource is an abstract entity that describes the common set of attributes shared by all concrete resources (e.g. TPE, EQUIPMENT) in the inventory.")
@Validated
@jakarta.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2021-07-08T09:52:18.013684600+03:00[Europe/Athens]")
/*
 * Lets a caller deserialize to Resource and get the right concrete subclass, rather than having to
 * guess it. "@type" here is free-form text (see ResourceTypeIdResolver), so the id is resolved by the
 * inventory's own rule instead of a @JsonSubTypes name match, and a null "@type" means logical.
 *
 * include=EXISTING_PROPERTY: the inherited "@type" field already serializes itself, so Jackson writes
 * no id of its own and the JSON a Resource produces is unchanged by this annotation.
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, include = JsonTypeInfo.As.EXISTING_PROPERTY,
		property = "@type", visible = true, defaultImpl = LogicalResource.class)
@JsonTypeIdResolver(ResourceTypeIdResolver.class)
@Entity(name = "RIResource")
public class Resource extends BaseRootNamedEntity {
	@JsonProperty("id")
@@ -584,6 +597,77 @@ public class Resource extends BaseRootNamedEntity {
		this.usageState = usageState;
	}

	/**
	 * Classifies this resource's health from its ITU-T X.731 state attributes.
	 *
	 * <p>{@code resourceStatus} is deliberately not consulted: it is inventory/pool bookkeeping
	 * ({@code AVAILABLE} = free for reservation, {@code RESERVED} = held by someone) and carries no
	 * information about whether the resource is working. {@code usageState} is not consulted either —
	 * a healthy resource carrying no load is legitimately {@code IDLE}.
	 *
	 * <p>Evaluation order matters. {@code SHUTDOWN} outranks everything, because a torn-down resource
	 * is gone whatever its operational state last reported. A resource is only ever judged healthy
	 * when it <b>explicitly</b> declares {@code administrativeState=UNLOCKED}: an unset attribute
	 * means the producer has not adopted this contract, and such a resource must neither promote nor
	 * demote a service.
	 *
	 * @return the health verdict; never null
	 */
	public ResourceHealth deriveHealth() {
		if (administrativeState == ResourceAdministrativeStateType.SHUTDOWN) {
			return ResourceHealth.GONE;
		}
		if (administrativeState == ResourceAdministrativeStateType.LOCKED) {
			return ResourceHealth.HELD;
		}
		if (operationalState == null || administrativeState == null) {
			return ResourceHealth.PENDING;
		}
		return operationalState == ResourceOperationalStateType.ENABLE
				? ResourceHealth.UP
				: ResourceHealth.DOWN;
	}

	/**
	 * Sets the ITU-T X.731 state attributes so that {@link #deriveHealth()} reports the given verdict.
	 * The inverse of {@code deriveHealth}, and the one place that decides how a health verdict is
	 * spelled out in attributes — callers that want to say "this resource is up" should not have to
	 * remember which pair of enums means that.
	 *
	 * <p>{@code resourceStatus} is untouched: health and pool bookkeeping are independent.
	 *
	 * @param health the verdict to express; {@code PENDING} clears both attributes, which is how a
	 *               resource that has not reported yet is represented
	 */
	public void applyHealth(ResourceHealth health) {
		if (health == null) {
			return;
		}
		switch (health) {
		case UP:
			this.operationalState = ResourceOperationalStateType.ENABLE;
			this.administrativeState = ResourceAdministrativeStateType.UNLOCKED;
			break;
		case DOWN:
			this.operationalState = ResourceOperationalStateType.DISABLE;
			this.administrativeState = ResourceAdministrativeStateType.UNLOCKED;
			break;
		case HELD:
			this.operationalState = ResourceOperationalStateType.ENABLE;
			this.administrativeState = ResourceAdministrativeStateType.LOCKED;
			break;
		case GONE:
			this.operationalState = ResourceOperationalStateType.DISABLE;
			this.administrativeState = ResourceAdministrativeStateType.SHUTDOWN;
			break;
		default:
			// PENDING: nothing is known about this resource.
			this.operationalState = null;
			this.administrativeState = null;
			break;
		}
	}

	

	@Override
+39
Changes for src/main/java/org/etsi/osl/tmf/ri639/model/ResourceHealth.java: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
package org.etsi.osl.tmf.ri639.model;

/**
 * The health verdict of a single {@link Resource}, derived from its ITU-T X.731 state attributes.
 *
 * <p>This is deliberately <b>not</b> {@link ResourceStatusType}. {@code ResourceStatusType} is
 * inventory/pool bookkeeping — {@code AVAILABLE} means "free in a pool, available for reservation"
 * and {@code RESERVED} means "held by someone" — and says nothing about whether the resource is
 * working. Health is expressed by {@link ResourceOperationalStateType} (is it functioning?) and
 * {@link ResourceAdministrativeStateType} (is it permitted to be used?).
 *
 * <p>{@link ResourceUsageStateType} is <b>not</b> consulted: a resource that is deployed and
 * perfectly healthy but carrying no load is legitimately {@code IDLE}, and most controllers cannot
 * observe utilisation at all.
 *
 * @see Resource#deriveHealth()
 * @see org.etsi.osl.tmf.sim638.model.Service#findNextStateBasedOnResourceList(java.util.List)
 */
public enum ResourceHealth {

  /** Functioning and permitted to be used: {@code operationalState=ENABLE, administrativeState=UNLOCKED}. */
  UP,

  /**
   * The resource has not told us where it stands yet — either state attribute is unset. Typically a
   * resource that is still being provisioned, or one written by a producer that predates the health
   * contract. A service must not be promoted on it, nor demoted because of it.
   */
  PENDING,

  /** Not functioning while still administratively in service: {@code operationalState=DISABLE}. */
  DOWN,

  /** Administratively barred from use: {@code administrativeState=LOCKED}. */
  HELD,

  /** Torn down: {@code administrativeState=SHUTDOWN}. The terminal verdict. */
  GONE
}
+18
Changes for src/main/java/org/etsi/osl/tmf/ri639/model/ResourceRefOrValue.java: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
package org.etsi.osl.tmf.ri639.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import org.springframework.validation.annotation.Validated;

@@ -16,6 +17,23 @@ import jakarta.validation.constraints.NotNull;
@jakarta.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2021-07-08T09:52:18.013684600+03:00[Europe/Athens]")
@Entity(name = "RIResourceRefOrVal")
@JsonIgnoreProperties( {"uuid"} )
/*
 * This is a concrete value type, not a polymorphic base: it is what a ResourceOrderItem carries, and
 * the column it is persisted in is a RIResourceRefOrVal, so no "@type" can ever change the class
 * read here. Resource's own @JsonTypeInfo must therefore not be inherited.
 *
 * If it is, the declared type of the property is ResourceRefOrValue while the inherited
 * defaultImpl is LogicalResource -- a *sibling*, not a subtype. Jackson cannot use a default it
 * cannot assign, so it is left with no fallback and a payload that omits "@type" (or sends it null)
 * fails with "missing type id property '@type'". That is a 400 on every POST /resourceOrder whose
 * order item carries a resource, and it is why reading a ResourceRefOrValue on its own broke too.
 *
 * Id.NONE says what is true rather than papering over it with a defaultImpl of this class: there is
 * no subtype of ResourceRefOrValue to choose between. "@type" is still read and written as the
 * ordinary inherited free-form field, so the wire format is unchanged. Reading a Resource still
 * resolves LogicalResource/PhysicalResource -- see ResourceTypeIdResolver.
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
public class ResourceRefOrValue extends Resource  {

	public void setId(@NotNull String id) {
Loading