Commit 2c027426 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fix Report HELD before UP on a real (non-simulation) create

parent e5f5f07d
Loading
Loading
Loading
Loading
+34 −0
Changes for .changelog/20261003_1734_report-held-before-up-on-create.md: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Report HELD before UP on a real (non-simulation) create

## Problem

`ResourceRepoService.createResource` had two different health progressions:

- **Simulation / planning**: the first callback reports the resource `HELD` (deployment requested,
  not usable yet), and a delayed second callback reports it `UP`.
- **Real create**: a single catalog write after `resourceLogic` finished, carrying
  `ENABLE`/`UNLOCKED` — so the resource went straight from `PENDING` to `UP`, with no `HELD` in between,
  even though `resourceLogic` may block for the whole deployment (e.g. `ResourceA`/`ResourceB` sleep).

## Change

In the non-simulation branch of `createResource`, before running the spec's `resourceLogic`, the
controller now writes a partial `ResourceUpdate` to the catalog carrying only the `HELD` X.731
attributes (operational/administrative state, as spelled by `Resource.applyHealth(HELD)`) and
`usageState=IDLE`. The existing final write then reports `UP`. Real creates now follow
`PENDING -> HELD -> UP`, matching the planning path.

A new private helper `healthUpdate(ResourceHealth, ResourceUsageStateType)` builds that partial update;
like `putHealth`, it asks the model's `applyHealth` how a verdict is spelled rather than re-tabulating
the mapping. Partial updates against the catalog follow the existing precedent of the
`ResourceA`/`ResourceB` worker threads.

`updateResource` and `deleteResource` are unchanged.

## Files

- `src/main/java/org/etsi/osl/example/gc/api/ResourceRepoService.java`

## Verification

- `mvn -o compile` succeeds. Not exercised against a running OpenSlice instance.
+1 −0
Changes for .changelog/index.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

| Doc | Description |
|---|---|
| [20261003_1734_report-held-before-up-on-create.md](20261003_1734_report-held-before-up-on-create.md) | A real (non-simulation) `createResource` now writes a partial `HELD` update to the catalog before running the spec's `resourceLogic`, so the resource goes `PENDING -> HELD -> UP` like the planning path instead of jumping straight from `PENDING` to `UP`. |
| [20261001_1230_architecture-diagram-two-paths.md](20261001_1230_architecture-diagram-two-paths.md) | Redrew the guide's architecture diagram to separate the production and planning paths, and to show that planning callbacks land in the internal tentative planning inventory. |
| [20261001_1200_move-docs-to-changelog.md](20261001_1200_move-docs-to-changelog.md) | Moved change docs from `docs/` to `.changelog/`; `docs/` keeps only `writing-an-openslice-controller.md`, and the README now points to it. |
| [20260901_1155_kubernetescluster-estimate-scales-with-nodecount.md](20260901_1155_kubernetescluster-estimate-scales-with-nodecount.md) | `KubernetesCluster.estimateProfile` now scales with the requested `nodeCount`: a fixed control-plane part plus a per-node increment, calibrated so the default 3-node cluster reproduces the spec's original flat profile. Reads `nodeCount` from the request (not the singleton's mutable field, which the background OPERATION callback would race on), following the `RadioEngineer` pattern; falls back to 3 nodes when the characteristic is absent, unparseable, or outside `1..500`. New `KubernetesClusterTest` (6 tests); suite 22/22 on the estimator group. |
+19 −0
Changes for src/main/java/org/etsi/osl/example/gc/api/ResourceRepoService.java: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -118,6 +118,11 @@ public class ResourceRepoService {
      return reported != null ? reported : toSimulatedResource(resourceid, res);
    }

    // Mirror the planning progression on the real catalog: report HELD before the deployment starts,
    // so the supporting service sees PENDING -> HELD -> UP instead of jumping straight to UP once
    // resourceLogic (which may block for the deployment) has finished.
    aCatalogClient.updateResourceById( resourceid, healthUpdate(ResourceHealth.HELD, ResourceUsageStateType.IDLE));

    ResourceUpdate resourceUpdate = simpleResourceMapper.resourceCreateToResourceUpdate(resourceRequested);
    resourceUpdate = spec.resourceLogic(resourceUpdate, resourceid, false);

@@ -125,6 +130,20 @@ public class ResourceRepoService {
    return aCatalogClient.updateResourceById( resourceid, resourceUpdate);
  }

  /**
   * A partial update carrying only the X.731 attributes for a health verdict, spelled out by
   * {@link Resource#applyHealth} for the same reason as {@link #putHealth}.
   */
  private static ResourceUpdate healthUpdate(ResourceHealth health, ResourceUsageStateType usage) {
    Resource spelled = new Resource();
    spelled.applyHealth(health);
    ResourceUpdate ru = new ResourceUpdate();
    ru.setOperationalState(spelled.getOperationalState());
    ru.setAdministrativeState(spelled.getAdministrativeState());
    ru.setUsageState(usage);
    return ru;
  }

  /** Spec name of a resource, or null when unset — unlike create/update, delete never resolved one. */
  private static String specNameOf(ResourceUpdate r) {
    return r != null && r.getResourceSpecification() != null ? r.getResourceSpecification().getName() : null;