1
- // Copyright (c) .NET Foundation. All rights reserved.
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the MIT License. See License.txt in the project root for license information.
3
3
4
4
using System . Threading . Tasks ;
@@ -41,27 +41,23 @@ public async Task<IActionResult> Assign([FromBody] EncryptedHostAssignmentContex
41
41
42
42
var assignmentContext = _startupContextProvider . SetContext ( encryptedAssignmentContext ) ;
43
43
44
- // before starting the assignment we want to perform as much
45
- // up front validation on the context as possible
46
- string error = await _instanceManager . ValidateContext ( assignmentContext ) ;
47
- if ( error != null )
48
- {
49
- return StatusCode ( StatusCodes . Status400BadRequest , error ) ;
50
- }
44
+ return await AssignInternal ( assignmentContext ) ;
45
+ }
51
46
52
- // Wait for Sidecar specialization to complete before returning ok.
53
- // This shouldn't take too long so ok to do this sequentially.
54
- error = await _instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
55
- if ( error != null )
47
+ [ HttpPost ]
48
+ [ Route ( "admin/instance/assign2" ) ]
49
+ [ Authorize ( Policy = PolicyNames . AdminAuthLevel ) ]
50
+ public async Task < IActionResult > Assign2 ( [ FromBody ] FunctionsWorkerContainerAssignmentContext workerAssignmentContext )
51
+ {
52
+ if ( workerAssignmentContext ? . AssignmentContext == null || workerAssignmentContext . AssignmentContext == null )
56
53
{
57
- return StatusCode ( StatusCodes . Status500InternalServerError , error ) ;
54
+ return BadRequest ( "Assignment context is missing." ) ;
58
55
}
59
56
60
- var succeeded = _instanceManager . StartAssignment ( assignmentContext ) ;
57
+ _logger . LogDebug ( $ "Starting container assignment for host : { Request ? . Host } ") ;
58
+ var assignmentContext = _startupContextProvider . SetContext ( workerAssignmentContext . AssignmentContext ) ;
61
59
62
- return succeeded
63
- ? Accepted ( )
64
- : StatusCode ( StatusCodes . Status409Conflict , "Instance already assigned" ) ;
60
+ return await AssignInternal ( assignmentContext ) ;
65
61
}
66
62
67
63
[ HttpGet ]
@@ -79,5 +75,30 @@ public IActionResult GetHttpHealthStatus()
79
75
// Reaching here implies that http health of the container is ok.
80
76
return Ok ( ) ;
81
77
}
78
+
79
+ private async Task < IActionResult > AssignInternal ( HostAssignmentContext assignmentContext )
80
+ {
81
+ // before starting the assignment we want to perform as much
82
+ // up front validation on the context as possible
83
+ string error = await _instanceManager . ValidateContext ( assignmentContext ) ;
84
+ if ( error != null )
85
+ {
86
+ return StatusCode ( StatusCodes . Status400BadRequest , error ) ;
87
+ }
88
+
89
+ // Wait for Sidecar specialization to complete before returning ok.
90
+ // This shouldn't take too long so ok to do this sequentially.
91
+ error = await _instanceManager . SpecializeMSISidecar ( assignmentContext ) ;
92
+ if ( error != null )
93
+ {
94
+ return StatusCode ( StatusCodes . Status500InternalServerError , error ) ;
95
+ }
96
+
97
+ var succeeded = _instanceManager . StartAssignment ( assignmentContext ) ;
98
+
99
+ return succeeded
100
+ ? Accepted ( )
101
+ : StatusCode ( StatusCodes . Status409Conflict , "Instance already assigned" ) ;
102
+ }
82
103
}
83
104
}
0 commit comments