cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/src/Entity/K8sDeployment.php
modules/cloud_service_providers/k8s/src/Entity/K8sDeployment.php
<?php
namespace Drupal\k8s\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Defines the Deployment entity.
*
* @ingroup k8s
*
* @ContentEntityType(
* id = "k8s_deployment",
* label = @Translation("Kubernetes Deployment"),
* handlers = {
* "view_builder" = "Drupal\k8s\Entity\K8sDeploymentViewBuilder",
* "list_builder" = "Drupal\cloud\Controller\CloudContentListBuilder",
* "views_data" = "Drupal\k8s\Entity\K8sDeploymentViewsData",
* "access" = "Drupal\k8s\Controller\K8sDeploymentAccessControlHandler",
* "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_deployment",
* admin_permission = "administer k8s deployment",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* },
* links = {
* "canonical" = "/clouds/k8s/{cloud_context}/deployment/{k8s_deployment}",
* "collection" = "/clouds/k8s/{cloud_context}/deployment",
* "add-form" = "/clouds/k8s/{cloud_context}/deployment/add",
* "edit-form" = "/clouds/k8s/{cloud_context}/deployment/{k8s_deployment}/edit",
* "delete-form" = "/clouds/k8s/{cloud_context}/deployment/{k8s_deployment}/delete",
* "delete-multiple-form" = "/clouds/k8s/{cloud_context}/deployment/delete_multiple",
* },
* field_ui_base_route = "k8s_deployment.settings"
* )
*/
class K8sDeployment extends K8sEntityBase implements K8sDeploymentInterface {
/**
* {@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 getStrategy() {
return $this->get('strategy');
}
/**
* {@inheritdoc}
*/
public function setStrategy($strategy) {
return $this->set('strategy', $strategy);
}
/**
* {@inheritdoc}
*/
public function getMinReadySeconds() {
return $this->get('min_ready_seconds');
}
/**
* {@inheritdoc}
*/
public function setMinReadySeconds($min_ready_seconds) {
return $this->set('min_ready_seconds', $min_ready_seconds);
}
/**
* {@inheritdoc}
*/
public function getRevisionHistoryLimit() {
return $this->get('revision_history_limit');
}
/**
* {@inheritdoc}
*/
public function setRevisionHistoryLimit($revision_history_limit) {
return $this->set('revision_history_limit', $revision_history_limit);
}
/**
* {@inheritdoc}
*/
public function getAvailableReplicas() {
return $this->get('available_replicas');
}
/**
* {@inheritdoc}
*/
public function setAvailableReplicas($available_replicas) {
return $this->set('available_replicas', $available_replicas);
}
/**
* {@inheritdoc}
*/
public function getCollisionCount() {
return $this->get('collision_count');
}
/**
* {@inheritdoc}
*/
public function setCollisionCount($collision_count) {
return $this->set('collision_count', $collision_count);
}
/**
* {@inheritdoc}
*/
public function getObservedGeneration() {
return $this->get('observed_generation');
}
/**
* {@inheritdoc}
*/
public function setObservedGeneration($observed_generation) {
return $this->set('observed_generation', $observed_generation);
}
/**
* {@inheritdoc}
*/
public function getReadyReplicas() {
return $this->get('ready_replicas');
}
/**
* {@inheritdoc}
*/
public function setReadyReplicas($ready_replicas) {
return $this->set('ready_replicas', $ready_replicas);
}
/**
* {@inheritdoc}
*/
public function getReplicas() {
return $this->get('replicas');
}
/**
* {@inheritdoc}
*/
public function setReplicas($replicas) {
return $this->set('replicas', $replicas);
}
/**
* {@inheritdoc}
*/
public function getUnavailableReplicas() {
return $this->get('unavailable_replicas');
}
/**
* {@inheritdoc}
*/
public function setUnavailableReplicas($unavailable_replicas) {
return $this->set('unavailable_replicas', $unavailable_replicas);
}
/**
* {@inheritdoc}
*/
public function getUpdatedReplicas() {
return $this->get('updated_replicas');
}
/**
* {@inheritdoc}
*/
public function setUpdatedReplicas($updated_replicas) {
return $this->set('updated_replicas', $updated_replicas);
}
/**
* {@inheritdoc}
*/
public function getDetail() {
return $this->get('detail')->value;
}
/**
* {@inheritdoc}
*/
public function setDetail($detail) {
return $this->set('detail', $detail);
}
/**
* {@inheritdoc}
*/
public function getCreationYaml() {
return $this->get('creation_yaml')->value;
}
/**
* {@inheritdoc}
*/
public function setCreationYaml($creation_yaml) {
return $this->set('creation_yaml', $creation_yaml);
}
/**
* {@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 Deployment entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Deployment entity.'))
->setReadOnly(TRUE);
$fields['cloud_context'] = BaseFieldDefinition::create('string')
->setRequired(TRUE)
->setLabel(t('Cloud Service Provider ID'))
->setDescription(t('A unique machine name for the cloud service provider.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The deployment name.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['namespace'] = BaseFieldDefinition::create('string')
->setLabel(t('Namespace'))
->setDescription(t('The namespace of deployment.'))
->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['strategy'] = BaseFieldDefinition::create('string')
->setLabel(t('Strategy'))
->setDescription(t('The deployment strategy to use to replace existing pods with new ones.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['min_ready_seconds'] = BaseFieldDefinition::create('integer')
->setLabel(t('Minimum ready seconds'))
->setDescription(t('Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['revision_history_limit'] = BaseFieldDefinition::create('integer')
->setLabel(t('Revision History Limit'))
->setDescription(t('The number of old ReplicaSets to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['available_replicas'] = BaseFieldDefinition::create('integer')
->setLabel(t('Available Replicas'))
->setDescription(t('Total number of available pods (ready for at least minReadySeconds) targeted by this deployment.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['collision_count'] = BaseFieldDefinition::create('integer')
->setLabel(t('Collision Count'))
->setDescription(t('Count of hash collisions for the Deployment. The Deployment controller uses this field as a collision avoidance mechanism when it needs to create the name for the newest ReplicaSet.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['observed_generation'] = BaseFieldDefinition::create('integer')
->setLabel(t('Observed Generation'))
->setDescription(t('The generation observed by the deployment controller.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['ready_replicas'] = BaseFieldDefinition::create('integer')
->setLabel(t('Ready Replicas'))
->setDescription(t('Total number of ready pods targeted by this deployment.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['replicas'] = BaseFieldDefinition::create('integer')
->setLabel(t('Replicas'))
->setDescription(t('Total number of non-terminated pods targeted by this deployment (their labels match the selector).'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['unavailable_replicas'] = BaseFieldDefinition::create('integer')
->setLabel(t('Unavailable Replicas'))
->setDescription(t('Total number of unavailable pods targeted by this deployment.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['updated_replicas'] = BaseFieldDefinition::create('integer')
->setLabel(t('Updated Replicas'))
->setDescription(t('Total number of non-terminated pods targeted by this deployment that have the desired template spec.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['detail'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Detail'))
->setDescription(t('Deployment 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['creation_yaml'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Creation YAML'))
->setDescription(t('The YAML content was used to create the entity.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'pre_string_formatter',
'weight' => -5,
]);
$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;
}
}
