chg: [galaxyCluster:push] Only push custom clusters that are contained in the

event getting pushed
pull/6120/head
mokaddem 2020-06-15 14:37:37 +02:00
parent a7085c82c8
commit 6854c81bff
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 72 additions and 31 deletions

View File

@ -6992,4 +6992,42 @@ class Event extends AppModel
}
}
}
public function extractAllTagNames($event)
{
$tags = array();
if (!empty($event['EventTag'])) {
foreach($event['EventTag'] as $eventTag) {
$tagName = $eventTag['Tag']['name'];
$tags[$tagName] = $tagName;
}
}
if (!empty($event['Attribute'])) {
foreach($event['Attribute'] as $attribute) {
foreach($attribute['AttributeTag'] as $attributeTag) {
$tagName = $attributeTag['Tag']['name'];
$tags[$tagName] = $tagName;
}
}
}
if (!empty($event['ShadowAttribute'])) {
foreach($event['ShadowAttribute'] as $attribute) {
foreach($attribute['AttributeTag'] as $attributeTag) {
$tagName = $attributeTag['Tag']['name'];
$tags[$tagName] = $tagName;
}
}
}
if (!empty($event['Object'])) {
foreach($event['Object'] as $object) {
foreach($object['Attribute'] as $attribute) {
foreach($attribute['AttributeTag'] as $attributeTag) {
$tagName = $attributeTag['Tag']['name'];
$tags[$tagName] = $tagName;
}
}
}
}
return $tags;
}
}

View File

@ -284,12 +284,13 @@ class Galaxy extends AppModel
}
$cluster['GalaxyCluster']['galaxy_id'] = $existingGalaxy['Galaxy']['id'];
$cluster['GalaxyCluster']['locked'] = true;
$saveResult = $this->GalaxyCluster->saveCluster($user, $cluster, $allowEdit=true);
if (empty($errors)) {
$results['imported']++;
$saveResult = $this->GalaxyCluster->captureCluster($user, $cluster, $fromPull=false);
if (empty($saveResult['errors'])) {
$results['imported'] += $saveResult['imported'];
} else {
$results['failed']++;
$results['errors'] = array_merge($results['errors'], $errors);
$results['ignored'] += $saveResult['ignored'];
$results['failed'] += $saveResult['failed'];
$results['errors'] = array_merge($results['errors'], $saveResult['errors']);
}
}
$results['success'] = !($results['failed'] > 0 && $results['imported'] == 0);

View File

@ -173,10 +173,11 @@ class GalaxyCluster extends AppModel
// Respecting ACL, save a cluster, its elements and set correct fields
public function saveCluster($user, $cluster, $allowEdit=false)
{
if (!$user['Role']['perm_galaxy_editor'] && !$user['Role']['perm_site_admin']) {
return false;
}
$errors = array();
if (!$user['Role']['perm_galaxy_editor'] && !$user['Role']['perm_site_admin']) {
$errors[] = __('Incorrect permission');
return $errors;
}
$galaxy = $this->Galaxy->find('first', array('conditions' => array(
'id' => $cluster['GalaxyCluster']['galaxy_id']
)));
@ -451,7 +452,7 @@ class GalaxyCluster extends AppModel
$this->GalaxyElement->captureElements($user, $cluster['GalaxyCluster']['GalaxyElement'], $savedCluster['GalaxyCluster']['id']);
}
if (!empty($cluster['GalaxyCluster']['GalaxyClusterRelation'])) {
$saveResult = $this->GalaxyClusterRelation->captureRelations($user, $savedCluster, $cluster['GalaxyCluster']['GalaxyClusterRelation'], $fromPull=true, $orgId=$orgId);
$saveResult = $this->GalaxyClusterRelation->captureRelations($user, $savedCluster, $cluster['GalaxyCluster']['GalaxyClusterRelation'], $fromPull=$fromPull);
if ($saveResult['failed'] > 0) {
$results['errors'][] = __('Issues while capturing relations have been logged.');
}

View File

@ -3052,8 +3052,17 @@ class Server extends AppModel
$event = $event[0];
$event['Event']['locked'] = 1;
$result = $this->Event->uploadEventToServer($event, $this->data, $HttpSocket);
$result = 'Success';
if ('Success' === $result) {
$successes[] = $event['Event']['id'];
if ($push['canPush'] || $push['canEditGalaxyCluster']) {
$clustersSuccesses = $this->syncGalaxyClusters($HttpSocket, $this->data, $user, $event);
} else {
$clustersSuccesses = array();
}
$successes = array_merge($successes, $clustersSuccesses);
} else {
$fails[$event['Event']['id']] = $result;
}
@ -3092,13 +3101,6 @@ class Server extends AppModel
$fails = array();
}
if ($push['canPush'] || $push['canEditGalaxyCluster']) {
$clustersSuccesses = $this->syncGalaxyClusters($HttpSocket, $this->data, $user);
} else {
$clustersSuccesses = array();
}
$successes = array_merge($successes, $clustersSuccesses);
$this->Log = ClassRegistry::init('Log');
$this->Log->create();
$this->Log->save(array(
@ -3147,7 +3149,7 @@ class Server extends AppModel
return $uuidList;
}
public function syncGalaxyClusters($HttpSocket, $server, $user)
public function syncGalaxyClusters($HttpSocket, $server, $user, $event)
{
$successes = array();
if (!$server['Server']['push_galaxy_clusters']) {
@ -3156,20 +3158,19 @@ class Server extends AppModel
$this->GalaxyCluster = ClassRegistry::init('GalaxyCluster');
$HttpSocket = $this->setupHttpSocket($server, $HttpSocket);
$elligibleClusters = $this->GalaxyCluster->getElligibleClustersToPush($user);
$clusterIds = $this->getClusterIdsFromServer($server, $HttpSocket, $elligibleClusters);
if (!empty($clusterIds)) {
// check each cluster push it when needed
foreach ($clusterIds as $k => $clusterId) {
$options = array('conditions' => array(
'GalaxyCluster.uuid' => $clusterId
));
$cluster = $this->GalaxyCluster->fetchGalaxyClusters($user, $options, $full=true);
if (!empty($cluster)) {
$cluster = $cluster[0];
$result = $this->GalaxyCluster->uploadClusterToServer($cluster, $server, $HttpSocket, $user);
if ($result === 'Success') {
$successes[] = __('GalaxyCluster %s', $cluster['GalaxyCluster']['uuid']);
}
$tagNames = $this->Event->extractAllTagNames($event);
if (!empty($tagNames)) {
$options = array(
'conditions' => array(
'GalaxyCluster.tag_name' => $tagNames,
'GalaxyCluster.default' => 0,
)
);
$clusters = $this->GalaxyCluster->fetchGalaxyClusters($user, $options, $full=true);
foreach ($clusters as $k => $cluster) {
$result = $this->GalaxyCluster->uploadClusterToServer($cluster, $server, $HttpSocket, $user);
if ($result === 'Success') {
$successes[] = __('GalaxyCluster %s', $cluster['GalaxyCluster']['uuid']);
}
}
}