cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/src/Entity/K8sJob.php
modules/cloud_service_providers/k8s/src/Entity/K8sJob.php
<?php
namespace Drupal\k8s\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Defines the Job entity.
*
* @ingroup k8s
*
* @ContentEntityType(
* id = "k8s_job",
* label = @Translation("Kubernetes Job"),
* handlers = {
* "view_builder" = "Drupal\k8s\Entity\K8sJobViewBuilder",
* "list_builder" = "Drupal\cloud\Controller\CloudContentListBuilder",
* "views_data" = "Drupal\k8s\Entity\K8sJobViewsData",
* "access" = "Drupal\k8s\Controller\K8sJobAccessControlHandler",
* "form" = {
* "add" = "Drupal\k8s\Form\K8sCreateForm",
* "edit" = "Drupal\k8s\Form\K8sEditForm",
* "delete" = "Drupal\k8s\Form\K8sDeleteForm",
* "delete-multiple-confirm" = "Drupal\k8s\Form\K8sDeleteMultipleForm",
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* },
* base_table = "k8s_job",
* admin_permission = "administer k8s job",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* },
* links = {
* "canonical" = "/clouds/k8s/{cloud_context}/job/{k8s_job}",
* "collection" = "/clouds/k8s/{cloud_context}/job",
* "add-form" = "/clouds/k8s/{cloud_context}/job/add",
* "edit-form" = "/clouds/k8s/{cloud_context}/job/{k8s_job}/edit",
* "delete-form" = "/clouds/k8s/{cloud_context}/job/{k8s_job}/delete",
* "delete-multiple-form" = "/clouds/k8s/{cloud_context}/job/delete_multiple",
* },
* field_ui_base_route = "k8s_job.settings"
* )
*/
class K8sJob extends K8sEntityBase implements K8sJobInterface {
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
return $this->set('name', $name);
}
/**
* {@inheritdoc}
*/
public function getNamespace() {
return $this->get('namespace')->value;
}
/**
* {@inheritdoc}
*/
public function setNamespace($namespace) {
return $this->set('namespace', $namespace);
}
/**
* {@inheritdoc}
*/
public function getLabels() {
return $this->get('labels');
}
/**
* {@inheritdoc}
*/
public function setLabels($labels) {
return $this->set('labels', $labels);
}
/**
* {@inheritdoc}
*/
public function getAnnotations() {
return $this->get('annotations');
}
/**
* {@inheritdoc}
*/
public function setAnnotations($annotations) {
return $this->set('annotations', $annotations);
}
/**
* {@inheritdoc}
*/
public function getImage() {
return $this->get('image');
}
/**
* {@inheritdoc}
*/
public function setImage($image) {
return $this->set('image', $image);
}
/**
* {@inheritdoc}
*/
public function getCompletions() {
return $this->get('completions');
}
/**
* {@inheritdoc}
*/
public function setCompletions($completions) {
return $this->set('completions', $completions);
}
/**
* {@inheritdoc}
*/
public function getParallelism() {
return $this->get('parallelism');
}
/**
* {@inheritdoc}
*/
public function setParallelism($parallelism) {
return $this->set('parallelism', $parallelism);
}
/**
* {@inheritdoc}
*/
public function getActive() {
return $this->get('active');
}
/**
* {@inheritdoc}
*/
public function setActive($active) {
return $this->set('active', $active);
}
/**
* {@inheritdoc}
*/
public function getFailed() {
return $this->get('failed');
}
/**
* {@inheritdoc}
*/
public function setFailed($failed) {
return $this->set('failed', $failed);
}
/**
* {@inheritdoc}
*/
public function getSucceeded() {
return $this->get('succeeded');
}
/**
* {@inheritdoc}
*/
public function setSucceeded($succeeded) {
return $this->set('succeeded', $succeeded);
}
/**
* {@inheritdoc}
*/
public function getDetail() {
return $this->get('detail')->value;
}
/**
* {@inheritdoc}
*/
public function setDetail($detail) {
return $this->set('detail', $detail);
}
/**
* {@inheritdoc}
*/
public function getRefreshed() {
return $this->get('refreshed')->value;
}
/**
* {@inheritdoc}
*/
public function setRefreshed($time) {
return $this->set('refreshed', $time);
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Job entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Job entity.'))
->setReadOnly(TRUE);
$fields['cloud_context'] = BaseFieldDefinition::create('string')
->setRequired(TRUE)
->setLabel(t('Cloud ID'))
->setDescription(t('A unique machine name for the cloud provider.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The job name.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['namespace'] = BaseFieldDefinition::create('string')
->setLabel(t('Namespace'))
->setDescription(t('The namespace of job.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['labels'] = BaseFieldDefinition::create('key_value')
->setLabel(t('Labels'))
->setDescription(t('Map of string keys and values that can be used to organize and categorize (scope and select) objects.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'type' => 'key_value_formatter',
'weight' => -5,
]);
$fields['annotations'] = BaseFieldDefinition::create('key_value')
->setLabel(t('Annotations'))
->setDescription(t('Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSetting('max_length', 4096)
->setDisplayOptions('view', [
'type' => 'key_value_formatter',
'weight' => -5,
]);
$fields['image'] = BaseFieldDefinition::create('string')
->setLabel(t('Image'))
->setDescription(t('Docker image name.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['completions'] = BaseFieldDefinition::create('integer')
->setLabel(t('Completions'))
->setDescription(t('Specifies the desired number of successfully finished pods the job should be run with.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['parallelism'] = BaseFieldDefinition::create('integer')
->setLabel(t('Parallelism'))
->setDescription(t('Specifies the maximum desired number of pods the job should run at any given time.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['active'] = BaseFieldDefinition::create('integer')
->setLabel(t('Active'))
->setDescription(t('The number of actively running pods.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['failed'] = BaseFieldDefinition::create('integer')
->setLabel(t('Failed'))
->setDescription(t('The number of pods which reached phase Failed.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['succeeded'] = BaseFieldDefinition::create('integer')
->setLabel(t('Succeeded'))
->setDescription(t('The number of pods which reached phase Succeeded.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['detail'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Detail'))
->setDescription(t('Job detail.'))
->setRequired(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'pre_string_formatter',
'weight' => -5,
])
->setDisplayOptions('form', [
'type' => 'string_textarea',
'settings' => [
'rows' => 20,
],
])
->addConstraint('yaml_array_data');
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
$fields['refreshed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Refreshed'))
->setDescription(t('The time that the entity was last refreshed.'));
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of the Pod entity author.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}
