Commit 9eee7c68 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fix for $12

parent 46523fb0
Loading
Loading
Loading
Loading
+43 −3
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public class KubernetesCRDV1 extends DomainModelDefinition
		implements ITMFRCM634_ModelTransformer, ITMFRI639_ModelTransformer {

	public static final String OSL_KUBCRD_RSPEC_NAME = "kubernetes-crd.openslice.io";
	public static final String OSL_KUBCRD_RSPEC_VERSION = "0.0.3";
	public static final String OSL_KUBCRD_RSPEC_VERSION = "0.0.4";
	public static final String OSL_KUBCRD_RSPEC_CATEGORY = "KubernetesCRD-apiextensions.k8s.io/v1";
	public static final String OSL_KUBCRD_RESOURCE_CATEGORY = "KubernetesCRD-apiextensions.k8s.io/v1";
	public static final String OSL_KUBCRD_RSPEC_TYPE = "LogicalResourceSpecification";
@@ -57,6 +57,20 @@ public class KubernetesCRDV1 extends DomainModelDefinition
    private String statusCheckValueUnknown;
    private String statusCheckValueSuspended;

    private String adminStateCheckValueLocked;
    private String adminStateCheckValueUnlocked;
    private String adminStateCheckValueShutdown;
    private String operStateCheckValueEnable;
    private String operStateCheckValueDisable;
    private String usageStateCheckValueIdle;
    private String usageStateCheckValueActive;
    private String usageStateCheckValueBusy;
    private String healthCheckValueUp;
    private String healthCheckValuePending;
    private String healthCheckValueDown;
    private String healthCheckValueHeld;
    private String healthCheckValueGone;


	@Builder
	public KubernetesCRDV1(String osl_KUBCRD_RSPEC_UUID, String uuid, String name, String version, String description, String category,
@@ -127,6 +141,19 @@ public class KubernetesCRDV1 extends DomainModelDefinition
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_RESERVED", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal the reserved status", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_UNKNOWN", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal the unknown status", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_SUSPENDED", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal the suspended status", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_ADMINSTATE_LOCKED", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal administrativeState=locked", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_ADMINSTATE_UNLOCKED", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal administrativeState=unlocked", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_ADMINSTATE_SHUTDOWN", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal administrativeState=shutdown", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_OPERSTATE_ENABLE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal operationalState=enable", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_OPERSTATE_DISABLE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal operationalState=disable", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_USAGESTATE_IDLE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal usageState=idle", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_USAGESTATE_ACTIVE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal usageState=active", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_USAGESTATE_BUSY", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal usageState=busy", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_UP", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=UP", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_PENDING", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=PENDING", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_DOWN", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=DOWN", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_HELD", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=HELD", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_GONE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=GONE", false);

//		rsc.addResourceSpecificationCharacteristicItemShort( "properties", "", EValueType.SET.getValue());
//		rsc.addResourceSpecificationCharacteristicItemShort( "additionalProperties", "", EValueType.SET.getValue());
@@ -210,6 +237,19 @@ public class KubernetesCRDV1 extends DomainModelDefinition
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_RESERVED", this.statusCheckValueReserved, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_UNKNOWN", this.statusCheckValueUnknown, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_SUSPENDED", this.statusCheckValueSuspended, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_ADMINSTATE_LOCKED", this.adminStateCheckValueLocked, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_ADMINSTATE_UNLOCKED", this.adminStateCheckValueUnlocked, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_ADMINSTATE_SHUTDOWN", this.adminStateCheckValueShutdown, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_OPERSTATE_ENABLE", this.operStateCheckValueEnable, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_OPERSTATE_DISABLE", this.operStateCheckValueDisable, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_USAGESTATE_IDLE", this.usageStateCheckValueIdle, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_USAGESTATE_ACTIVE", this.usageStateCheckValueActive, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_USAGESTATE_BUSY", this.usageStateCheckValueBusy, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_UP", this.healthCheckValueUp, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_PENDING", this.healthCheckValuePending, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_DOWN", this.healthCheckValueDown, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_HELD", this.healthCheckValueHeld, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_GONE", this.healthCheckValueGone, EValueType.TEXT.getValue());



+111 −38
Original line number Diff line number Diff line
@@ -13,9 +13,11 @@ import org.etsi.osl.tmf.rcm634.model.ResourceSpecificationRef;
import org.etsi.osl.tmf.rcm634.model.ResourceSpecificationUpdate;
import org.etsi.osl.tmf.ri639.model.ResourceCreate;
import org.etsi.osl.tmf.ri639.model.ResourceAdministrativeStateType;
import org.etsi.osl.tmf.ri639.model.ResourceHealth;
import org.etsi.osl.tmf.ri639.model.ResourceOperationalStateType;
import org.etsi.osl.tmf.ri639.model.ResourceStatusType;
import org.etsi.osl.tmf.ri639.model.ResourceUpdate;
import org.etsi.osl.tmf.ri639.model.ResourceUsageStateType;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@@ -32,7 +34,7 @@ public class KubernetesCRV1 extends DomainModelDefinition

	/** Label stamped by the cridge watcher when the CR is deleted from the cluster. */
	public static final String OSL_LABEL_DELETED = "org.etsi.osl.deleted";
	public static final String OSL_KUBCRV1_RSPEC_VERSION = "0.0.4";
	public static final String OSL_KUBCRV1_RSPEC_VERSION = "0.0.5";
	public static final String OSL_KUBCRV1_RSPEC_CATEGORY = "KubernetesCRV1-apiextensions.k8s.io/v1";
	public static final String OSL_KUBCRV1_RSPEC_TYPE = "LogicalResourceSpecification";
	public static final String OSL_KUBCRV1_RSPEC_DESCRIPTION = "This Specification is used to describe a generic KubernetesCRV1";
@@ -59,12 +61,39 @@ public class KubernetesCRV1 extends DomainModelDefinition
    private String statusCheckValueReserved;
    private String statusCheckValueUnknown;
    private String statusCheckValueSuspended;
    private String adminStateCheckValueLocked;
    private String adminStateCheckValueUnlocked;
    private String adminStateCheckValueShutdown;
    private String operStateCheckValueEnable;
    private String operStateCheckValueDisable;
    private String usageStateCheckValueIdle;
    private String usageStateCheckValueActive;
    private String usageStateCheckValueBusy;
    private String healthCheckValueUp;
    private String healthCheckValuePending;
    private String healthCheckValueDown;
    private String healthCheckValueHeld;
    private String healthCheckValueGone;

    /** Pool/inventory bookkeeping only — never health. Drives {@code resourceStatus}. */
    private ResourceStatusType statusValue;

    /**
     * The producer's resolved ITU-T X.731 view of the CR. {@code healthValue} is the convenient
     * path (translated to the operationalState/administrativeState pair by {@link #applyState});
     * the individual attributes, when set, win over whatever {@code healthValue} implied.
     */
    private ResourceHealth healthValue;
    private ResourceOperationalStateType operationalStateValue;
    private ResourceAdministrativeStateType administrativeStateValue;
    private ResourceUsageStateType usageStateValue;

	@Builder
	public KubernetesCRV1(String osl_KUBCRV1_RSPEC_UUID, String uuid, String name, String version, String description, String category,
			String clusterMasterURL, String currentContextCluster, String fullResourceName, String namespace,
			String kind, String apiGroup, String uID, String metadata, ResourceStatusType statusValue,
			ResourceHealth healthValue, ResourceOperationalStateType operationalStateValue,
			ResourceAdministrativeStateType administrativeStateValue, ResourceUsageStateType usageStateValue,
			String yaml,
			String json) {
		super(uuid, name, version, description, category);
@@ -80,6 +109,10 @@ public class KubernetesCRV1 extends DomainModelDefinition
		this.yaml = yaml;
        this.json = json;
        this.statusValue = statusValue;
        this.healthValue = healthValue;
        this.operationalStateValue = operationalStateValue;
        this.administrativeStateValue = administrativeStateValue;
        this.usageStateValue = usageStateValue;
		this.properties = new HashMap<>();
		this.additionalProperties = new HashMap<>();	
	}
@@ -132,6 +165,19 @@ public class KubernetesCRV1 extends DomainModelDefinition
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_RESERVED", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal the reserved status", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_UNKNOWN", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal the unknown status", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_SUSPENDED", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal the suspended status", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_ADMINSTATE_LOCKED", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal administrativeState=locked", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_ADMINSTATE_UNLOCKED", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal administrativeState=unlocked", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_ADMINSTATE_SHUTDOWN", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal administrativeState=shutdown", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_OPERSTATE_ENABLE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal operationalState=enable", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_OPERSTATE_DISABLE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal operationalState=disable", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_USAGESTATE_IDLE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal usageState=idle", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_USAGESTATE_ACTIVE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal usageState=active", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_USAGESTATE_BUSY", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal usageState=busy", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_UP", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=UP", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_PENDING", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=PENDING", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_DOWN", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=DOWN", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_HELD", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=HELD", false);
        rsc.addResourceSpecificationCharacteristicItemShort( "_CR_CHECKVAL_HEALTH_GONE", "", EValueType.TEXT.getValue(), "Used for providing the equivalent value from resource to signal health=GONE", false);

//		rsc.addResourceSpecificationCharacteristicItemShort( "properties", "", EValueType.SET.getValue());
//		rsc.addResourceSpecificationCharacteristicItemShort( "additionalProperties", "", EValueType.SET.getValue());
@@ -194,9 +240,22 @@ public class KubernetesCRV1 extends DomainModelDefinition
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_RESERVED", this.statusCheckValueReserved, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_UNKNOWN", this.statusCheckValueUnknown, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_SUSPENDED", this.statusCheckValueSuspended, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_ADMINSTATE_LOCKED", this.adminStateCheckValueLocked, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_ADMINSTATE_UNLOCKED", this.adminStateCheckValueUnlocked, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_ADMINSTATE_SHUTDOWN", this.adminStateCheckValueShutdown, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_OPERSTATE_ENABLE", this.operStateCheckValueEnable, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_OPERSTATE_DISABLE", this.operStateCheckValueDisable, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_USAGESTATE_IDLE", this.usageStateCheckValueIdle, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_USAGESTATE_ACTIVE", this.usageStateCheckValueActive, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_USAGESTATE_BUSY", this.usageStateCheckValueBusy, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_UP", this.healthCheckValueUp, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_PENDING", this.healthCheckValuePending, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_DOWN", this.healthCheckValueDown, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_HELD", this.healthCheckValueHeld, EValueType.TEXT.getValue());
        rs.addResourceCharacteristicItemShort("_CR_CHECKVAL_HEALTH_GONE", this.healthCheckValueGone, EValueType.TEXT.getValue());

        rs.resourceStatus( this.statusValue );
        applyHealth( rs );
        applyState( rs );

		if (this.properties != null)
			this.properties.forEach((kPropName, vProVal) -> {
@@ -216,51 +275,65 @@ public class KubernetesCRV1 extends DomainModelDefinition
	}

	/**
	 * Declares the CR's health with the ITU-T X.731 state attributes, derived from the same status
	 * label the operator already configures through {@code org.etsi.osl.statusCheckValue*}.
	 * Declares the CR's ITU-T X.731 state attributes on the resource, from what the producer
	 * reported — <b>not</b> from {@code resourceStatus}, which is inventory/pool bookkeeping and
	 * says nothing about whether the CR is working.
	 *
	 * <p>These attributes — not {@code resourceStatus}, which is inventory/pool bookkeeping — are what
	 * {@code Service.findNextStateBasedOnResourceList} folds into the supported service's state. A CR
	 * whose status has not been recognised yet is left with both attributes unset: that reads as
	 * "pending", which neither promotes nor demotes the service.
	 * <p>operationalState / administrativeState are what
	 * {@code Service.findNextStateBasedOnResourceList} folds into the supported service's state;
	 * usageState is orthogonal. The producer may report a {@link ResourceHealth} verdict via
	 * {@code healthValue} — translated here to the operationalState/administrativeState pair the
	 * same way {@code Resource.applyHealth} does, since {@code ResourceCreate} has no such helper.
	 * When {@code healthValue} is set it is authoritative: the individual
	 * {@code operationalStateValue} / {@code administrativeStateValue} / {@code usageStateValue}
	 * attributes are consulted only when no verdict was given. A CR with nothing set is left with
	 * both health attributes unset: that reads as "pending", which neither promotes nor demotes
	 * the service.
	 */
	private void applyHealth(ResourceCreate rs) {
	private void applyState(ResourceCreate rs) {

		// A CR the watcher saw disappear is gone, whatever its last observed status said.
		// A CR the watcher saw disappear is gone, whatever else was reported.
		if (this.properties != null && this.properties.get(OSL_LABEL_DELETED) != null) {
			rs.operationalState(ResourceOperationalStateType.DISABLE)
					.administrativeState(ResourceAdministrativeStateType.SHUTDOWN);
			return;
		}

		if (this.statusValue == null) {
			return;
		}

		switch (this.statusValue) {
		case AVAILABLE:
		if (this.healthValue != null) {
			switch (this.healthValue) {
			case UP:
				rs.operationalState(ResourceOperationalStateType.ENABLE)
						.administrativeState(ResourceAdministrativeStateType.UNLOCKED);
				break;
		case RESERVED:
		case STANDBY:
			// Not yet released for use by the service that ordered it.
			rs.operationalState(ResourceOperationalStateType.DISABLE)
					.administrativeState(ResourceAdministrativeStateType.LOCKED);
			break;
		case ALARM:
			case DOWN:
				// In service, but not working.
				rs.operationalState(ResourceOperationalStateType.DISABLE)
						.administrativeState(ResourceAdministrativeStateType.UNLOCKED);
				break;
		case SUSPENDED:
			case HELD:
				rs.operationalState(ResourceOperationalStateType.ENABLE)
						.administrativeState(ResourceAdministrativeStateType.LOCKED);
				break;
			case GONE:
				rs.operationalState(ResourceOperationalStateType.DISABLE)
						.administrativeState(ResourceAdministrativeStateType.SHUTDOWN);
				break;
			default:
			// UNKNOWN, or a status this mapping does not recognise: say nothing about health.
				// PENDING: nothing is known about this resource; leave both attributes unset.
				break;
			}
			return;
		}

		if (this.operationalStateValue != null) {
			rs.operationalState(this.operationalStateValue);
		}
		if (this.administrativeStateValue != null) {
			rs.administrativeState(this.administrativeStateValue);
		}
		if (this.usageStateValue != null) {
			rs.usageState(this.usageStateValue);
		}
	}

	@Override