Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99187134
DrydockLocalHostBlueprintImplementation.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jan 22, 04:04
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Jan 24, 04:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23724821
Attached To
rPH Phabricator
DrydockLocalHostBlueprintImplementation.php
View Options
<?php
final
class
DrydockLocalHostBlueprintImplementation
extends
DrydockBlueprintImplementation
{
public
function
isEnabled
()
{
return
false
;
}
public
function
getBlueprintName
()
{
return
pht
(
'Local Host'
);
}
public
function
getDescription
()
{
return
pht
(
'Allows Drydock to run on the local host.'
);
}
public
function
canAllocateMoreResources
(
array
$pool
)
{
assert_instances_of
(
$pool
,
'DrydockResource'
);
// The localhost can be allocated only once.
foreach
(
$pool
as
$resource
)
{
if
(
$resource
->
getBlueprintClass
()
==
$this
->
getBlueprintClass
())
{
return
false
;
}
}
return
true
;
}
protected
function
executeAllocateResource
(
DrydockLease
$lease
)
{
// TODO: Don't hard-code this.
$path
=
'/var/drydock/'
;
if
(!
Filesystem
::
pathExists
(
$path
))
{
throw
new
Exception
(
"Path '{$path}' does not exist!"
);
}
Filesystem
::
assertIsDirectory
(
$path
);
Filesystem
::
assertWritable
(
$path
);
$resource
=
$this
->
newResourceTemplate
(
'Host (localhost)'
);
$resource
->
setStatus
(
DrydockResourceStatus
::
STATUS_OPEN
);
$resource
->
setAttribute
(
'path'
,
$path
);
$resource
->
setAttribute
(
'remote'
,
'false'
);
$resource
->
setAttribute
(
'preallocated'
,
'false'
);
$resource
->
save
();
return
$resource
;
}
protected
function
canAllocateLease
(
DrydockResource
$resource
,
DrydockLease
$lease
)
{
return
false
;
}
protected
function
shouldAllocateLease
(
DrydockResource
$resource
,
DrydockLease
$lease
,
array
$other_leases
)
{
return
true
;
}
protected
function
executeAcquireLease
(
DrydockResource
$resource
,
DrydockLease
$lease
)
{
$lease_id
=
$lease
->
getID
();
$full_path
=
$resource
->
getAttribute
(
'path'
).
$lease_id
.
'/'
;
$cmd
=
$lease
->
getInterface
(
'command'
);
$cmd
->
execx
(
'mkdir %s'
,
$full_path
);
$lease
->
setAttribute
(
'path'
,
$full_path
);
}
public
function
getType
()
{
return
'host'
;
}
public
function
getInterface
(
DrydockResource
$resource
,
DrydockLease
$lease
,
$type
)
{
switch
(
$type
)
{
case
'command'
:
return
new
DrydockLocalCommandInterface
();
}
throw
new
Exception
(
"No interface of type '{$type}'."
);
}
}
Event Timeline
Log In to Comment