Skip to content
GitLab
    • Explore Projects Groups Topics Snippets
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • fusiondirectory-orchestrator fusiondirectory-orchestrator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • fusiondirectoryfusiondirectory
  • fusiondirectory-orchestratorfusiondirectory-orchestrator
  • Merge requests
  • !66
An error occurred while fetching the assigned milestone of the selected merge_request.

Resolve "[Orchestrator] - lifeCycle prolongation adds time from date of process and not from resource end date"

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged dockx thibault requested to merge 62-orchestrator-lifecycle-prolongation-adds-time-from-date-of-process-and-not-from-resource-end-date into dev 6 months ago
  • Overview 0
  • Commits 3
  • Pipelines 4
  • Changes 1

Related to #62 (closed)

Viewing commit a36a5c98
Prev Next
Show latest version
1 file
+ 63
− 45

    Preferences

    File browser
    Compare changes
  • Verified
    a36a5c98
    dockx thibault
    :sparkles: Feat(Orchestrator) - small refactor · a36a5c98
    dockx thibault authored 5 months ago
    Adds better readability
plugins/tasks/LifeCycle.php
+ 63
− 45
  • View file @ a36a5c98

  • Edit in single-file editor

  • Open in Web IDE


@@ -181,68 +181,86 @@ class LifeCycle implements EndpointInterface
*/
protected function updateLifeCycle (array $lifeCycleBehavior, string $userDN, array $currentUserLifeCycle)
{
// Will contain the supann resource to be updated
$matchedResource = '';
// Init return value
$result = '';
// Hosting the final entry of supann attributes to be pushed to LDAP
$ldapEntry = [];
// Only keep the supann state from the received array and removing the count key
$userStateHistory = $currentUserLifeCycle[0]['supannressourceetatdate'];
$this->gateway->unsetCountKeys($userStateHistory);
// Hosting the final entry of supann attributes to be pushed to LDAP
$ldapEntry = [];
// Extracting values of desired post-state behavior
$newEntry['Resource'] = $lifeCycleBehavior[0]['fdtaskslifecyclepostresource'][0];
$newEntry['State'] = $lifeCycleBehavior[0]['fdtaskslifecyclepoststate'][0];
$newEntry['SubState'] = $lifeCycleBehavior[0]['fdtaskslifecyclepostsubstate'][0] ?? ''; //SubState is optional
$newEntry['EndDate'] = $lifeCycleBehavior[0]['fdtaskslifecyclepostenddate'][0] ?? 0; //EndDate is optional
$newEntry = $this->prepareNewEntry($lifeCycleBehavior[0]);
// Prepare the ldap entry to be modified
// Create the new resource without start / end date
$newResource = "{" . $newEntry['Resource'] . "}" . $newEntry['State'] . ":" . $newEntry['SubState'];
// Used to compare if the resource exists in history
// Get the resource name, it will be used to compare if the resource exists in history
$newResourceName = $this->returnSupannResourceBetweenBrackets($newResource);
// Iterate through the supann state and get a match
foreach ($userStateHistory as $value) {
// Extract resource in curly braces (brackets) from the current supannRessourceEtatDate
$currentResource = $this->returnSupannResourceBetweenBrackets($value);
// Get the resource matched
if ($currentResource === $newResourceName) {
$matchedResource = $value;
break;
// Find a matching resource in the user state history
$matchedResource = $this->findMatchedResource($userStateHistory, $newResourceName);
if ($matchedResource) {
// Fetch the end date of the matched resource.
$currentEndDate = $this->extractCurrentEndDate($matchedResource);
// Create a DateTime object from the string
$currentEndDateObject = DateTime::createFromFormat("Ymd", $currentEndDate);
$currentEndDateObject->modify("+" . $newEntry['EndDate'] . " days");
$finalRessourceEtatDate = $newResource . ':' . $currentEndDate . ':' . $currentEndDateObject->format('Ymd');
// Iterate again through the supann state and get a match
foreach ($userStateHistory as $userState => $value) {
// Extract resource in curly braces (brackets) from the current supannRessourceEtatDate
$currentResource = $this->returnSupannResourceBetweenBrackets($value);
// Get the resource matched
if ($currentResource === $newResourceName) {
$userStateHistory[$userState] = $finalRessourceEtatDate;
break;
}
}
}
// Fetch the end date of the matched resource.
$currentEndDate = $this->extractCurrentEndDate($matchedResource);
// Create a DateTime object from the string
$currentEndDateObject = DateTime::createFromFormat("Ymd", $currentEndDate);
$currentEndDateObject->modify("+" . $newEntry['EndDate'] . " days");
$finalRessourceEtatDate = $newResource . ':' . $currentEndDate . ':' . $currentEndDateObject->format('Ymd');
// Iterate again through the supann state and get a match
foreach ($userStateHistory as $userState => $value) {
// Extract resource in curly braces (brackets) from the current supannRessourceEtatDate
$currentResource = $this->returnSupannResourceBetweenBrackets($value);
// Get the resource matched
if ($currentResource === $newResourceName) {
$userStateHistory[$userState] = $finalRessourceEtatDate;
break;
// Creation of the ldap entry
$ldapEntry['supannRessourceEtatDate'] = $userStateHistory;
try {
$result = ldap_modify($this->gateway->ds, $userDN, $ldapEntry);
} catch (Exception $e) {
$result = json_encode(["Ldap Error" => "$e"]);
}
}
return $result;
}
// Creation of the ldap entry
$ldapEntry['supannRessourceEtatDate'] = $userStateHistory;
try {
$result = ldap_modify($this->gateway->ds, $userDN, $ldapEntry);
} catch (Exception $e) {
$result = json_encode(["Ldap Error" => "$e"]);
/**
* @param array $userStateHistory
* @param string $newResourceName
* @return string|null
* Note : Simple helper method to return the matched resource.
*/
private function findMatchedResource(array $userStateHistory, string $newResourceName): ?string
{
foreach ($userStateHistory as $value) {
if ($this->returnSupannResourceBetweenBrackets($value) === $newResourceName) {
return $value;
}
}
return null;
}
return $result;
/**
* @param array $lifeCycleBehavior
* @return array
* Simple helper method for readiness.
*/
private function prepareNewEntry(array $lifeCycleBehavior): array
{
return [
'Resource' => $lifeCycleBehavior['fdtaskslifecyclepostresource'][0],
'State' => $lifeCycleBehavior['fdtaskslifecyclepoststate'][0],
'SubState' => $lifeCycleBehavior['fdtaskslifecyclepostsubstate'][0] ?? '',
'EndDate' => $lifeCycleBehavior['fdtaskslifecyclepostenddate'][0] ?? 0,
];
}
/**
Assignee
dockx thibault's avatar
dockx thibault
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 Participants
Reference:
Source branch: 62-orchestrator-lifecycle-prolongation-adds-time-from-date-of-process-and-not-from-resource-end-date

Menu

Explore Projects Groups Topics Snippets