Skip to content

Commit

Permalink
refactor(apply): remove apply summary and overview table
Browse files Browse the repository at this point in the history
The apply command provides an overview of how much time it may take
and the actions that will be performed during apply. However, the
calculation was based on estimates and are incorrect. Similary, the
actions are also incorrect at many places and neither do we need it.

This commit removes the chunk of code that prints that info.

Wrike Ticket: https://www.wrike.com/open.htm?id=1183537395
  • Loading branch information
pallabpain authored and ankitrgadiya committed Jul 30, 2024
1 parent 7348be2 commit 7581edc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 68 deletions.
5 changes: 4 additions & 1 deletion riocli/apply/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from riocli.apply.template import template
from riocli.apply.util import process_files_values_secrets
from riocli.constants import Colors
from riocli.utils import print_centered_text


@click.command(
Expand Down Expand Up @@ -74,7 +75,7 @@ def apply(
click.secho('No files specified', fg=Colors.RED)
raise SystemExit(1)

click.secho("----- Files Processed ----", fg=Colors.YELLOW)
print_centered_text('Files Processed')
for file in glob_files:
click.secho(file, fg=Colors.YELLOW)

Expand All @@ -93,6 +94,7 @@ def apply(
if not silent and not dryrun:
click.confirm("Do you want to proceed?", default=True, abort=True)

print_centered_text('Applying Manifests')
rc.apply(dryrun=dryrun, workers=workers, retry_count=retry_count, retry_interval=retry_interval)


Expand Down Expand Up @@ -137,4 +139,5 @@ def delete(
if not silent and not dryrun:
click.confirm("Do you want to proceed?", default=True, abort=True)

print_centered_text('Deleting Resources')
rc.delete(dryrun=dryrun)
70 changes: 3 additions & 67 deletions riocli/apply/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import json
import queue
import threading
Expand All @@ -21,32 +20,18 @@
import click
import jinja2
import yaml
from tabulate import tabulate

from riocli.apply.resolver import ResolverCache
from riocli.config import Configuration
from riocli.constants import Colors, Symbols
from riocli.utils import dump_all_yaml, print_separator, run_bash
from riocli.utils import dump_all_yaml, run_bash
from riocli.utils.graph import Graphviz
from riocli.utils.spinner import with_spinner


class Applier(object):
DEFAULT_MAX_WORKERS = 6

EXPECTED_TIME = {
"organization": 3,
"project": 3,
"secret": 3,
"package": 3,
"staticroute": 3,
"disk": 180,
"deployment": 240,
"network": 120,
"device": 5,
"user": 3,
}

def __init__(self, files: typing.List, values, secrets):
self.environment = None
self.input_file_paths = files
Expand Down Expand Up @@ -179,28 +164,6 @@ def parse_dependencies(
self._add_graph_node(key)
number_of_objects = number_of_objects + 1

resource_list = []
total_time = 0

for node in copy.deepcopy(self.graph).static_order():
action = 'UPDATE'
if not self.resolved_objects[node]['src'] == 'remote':
action = 'CREATE'
elif delete:
action = 'DELETE'
kind = node.split(":")[0]
expected_time = round(
self.EXPECTED_TIME.get(kind.lower(), 5) / 60, 2)
total_time += expected_time
resource_list.append([node, action, expected_time])

if not template:
self._display_context(
total_time=total_time,
total_objects=number_of_objects,
resource_list=resource_list
)

if check_missing:
missing_resources = []
for key, item in self.resolved_objects.items():
Expand Down Expand Up @@ -299,7 +262,7 @@ def _load_file_content(self, file_name, is_value=False, is_secret=False):
loaded = yaml.safe_load_all(data)
loaded_data = list(loaded)
except yaml.YAMLError as e:
raise Exception(f'Failed to parse {file_name}: {str(ex)}')
raise Exception(f'Failed to parse {file_name}: {str(e)}')

if not loaded_data:
click.secho('{} file is empty'.format(file_name))
Expand Down Expand Up @@ -357,8 +320,7 @@ def _resolve_dependency(self, dependent_key, dependency):
dependent_key, obj_guid, dependency, obj)

if (name_or_guid == obj_name) and (
'version' in dependency and obj[
'packageVersion'] == dependency.get('version')):
'version' in dependency and obj['packageVersion'] == dependency.get('version')):
self._add_remote_object_to_resolve_tree(
dependent_key, obj_guid, dependency, obj)

Expand Down Expand Up @@ -409,32 +371,6 @@ def show_dependency_graph(self):
self.diagram.visualize()

# Utils
def _display_context(
self,
total_time: int,
total_objects: int,
resource_list: typing.List
) -> None:
headers = [
click.style('Resource Context', bold=True, fg=Colors.YELLOW)]
context = [
['Expected Time (mins)', round(total_time, 2)],
['Files', len(self.files)],
['Resources', total_objects],
]
click.echo(tabulate(context, headers=headers,
tablefmt='simple', numalign='center'))

# Display Resource Inventory
headers = []
for header in ['Resource', 'Action', 'Expected Time (mins)']:
headers.append(click.style(header, fg=Colors.YELLOW, bold=True))

print_separator()
click.echo(tabulate(resource_list, headers=headers,
tablefmt='simple', numalign='center'))
print_separator()

@staticmethod
def _get_attr(obj, accept_keys):
metadata = None
Expand Down
6 changes: 6 additions & 0 deletions riocli/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,9 @@ def sanitize_label(name):
r = r + c

return r


def print_centered_text(text: str, color: str = Colors.YELLOW):
col, _ = get_terminal_size()
text = click.style(f' {text} '.center(col, '-'), fg=color, bold=True)
click.echo(text)

0 comments on commit 7581edc

Please sign in to comment.