Skip to content

Commit

Permalink
Modify data center config #243
Browse files Browse the repository at this point in the history
  • Loading branch information
sayantam committed Aug 25, 2021
1 parent 8db7579 commit ab42669
Show file tree
Hide file tree
Showing 22 changed files with 1,116 additions and 407 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.2'
services:
web:
image: "hailstorm3/hailstorm-web-client:1.8.10"
image: "hailstorm3/hailstorm-web-client:1.9.10"
ports:
- "8080:80"
networks:
Expand All @@ -22,7 +22,7 @@ services:
- "start.sh"

hailstorm-api:
image: "hailstorm3/hailstorm-api:1.0.18"
image: "hailstorm3/hailstorm-api:1.0.19"
ports:
- "4567:8080"
environment:
Expand Down
10 changes: 5 additions & 5 deletions hailstorm-api/app/api/clusters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@

patch '/projects/:project_id/clusters/:id' do |project_id, id|
found_project = Hailstorm::Model::Project.find(project_id)
project_config = ProjectConfiguration.find_by_project_id!(found_project.id)
return 422 unless found_project.current_execution_cycle.nil?

project_config = ProjectConfiguration.find_by_project_id!(found_project.id)
# @type [Hailstorm::Support::Configuration] hailstorm_config
hailstorm_config = deep_decode(project_config.stringified_config)
matched_cluster_cfg = find_cluster_cfg(hailstorm_config, id)
Expand All @@ -103,12 +104,11 @@
is_project_live = !found_project.load_agents.empty?
data.each_pair do |key, value|
field_name = key.underscore.to_sym
return 422 if matched_cluster_cfg.active == false && field_name != :active
return 422 if field_name == :region
return 422 if field_name == :base_ami && matched_cluster_cfg.base_ami.blank?
return 422 if is_project_live && field_name != :max_threads_per_agent
return 422 unless patch_request_valid?(matched_cluster_cfg, field_name)

matched_cluster_cfg.send("#{field_name}=", value)
field_value = query_field_value(matched_cluster_cfg, field_name: field_name, value: value)
matched_cluster_cfg.send("#{field_name}=", field_value)
end

project_config.update!(stringified_config: deep_encode(hailstorm_config))
Expand Down
24 changes: 24 additions & 0 deletions hailstorm-api/app/helpers/clusters_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,28 @@ def string_to_id(str)
def to_array(any)
any.is_a?(Array) ? any : [any]
end

# @param [Hailstorm::Support::Configuration::ClusterBase] cluster_config
# @param [String] field_name
# @param [Object] value
# @return [Object]
def query_field_value(cluster_config, field_name:, value:)
field_value = value
if field_name == :ssh_identity && cluster_config.cluster_type == :data_center
field_value = "#{value['path']}/#{value['name']}"
end

field_value
end

# @param [Hailstorm::Support::Configuration::ClusterBase] cluster_config
# @param [String] field_name
def patch_request_valid?(cluster_config, field_name)
return false if cluster_config.active == false && field_name != :active
return false if field_name == :region
return false if field_name == :base_ami && cluster_config.base_ami.blank?
return false if field_name == :code

true
end
end
2 changes: 1 addition & 1 deletion hailstorm-api/app/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# Version
module Hailstorm
module Api
VERSION = '1.0.18'
VERSION = '1.0.19'
end
end
124 changes: 98 additions & 26 deletions hailstorm-api/spec/api/clusters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,30 +381,8 @@
@hailstorm_config = Hailstorm::Support::Configuration.new
end

it 'should update the cluster attributes in project configuration' do
@hailstorm_config.clusters(:data_center) do |dc|
# @type [Hailstorm::Support::Configuration::DataCenter] dc
dc.title = 'Ice station Zebra'
dc.user_name = 'ubuntu'
dc.ssh_identity = '123/foo.pem'
dc.machines = %w[172.16.0.10 172.16.0.20 172.16.0.30]
dc.ssh_port = 8022
dc.cluster_code = 'ice-station-zebra-119'
dc.active = false
end

ProjectConfiguration.create!(project: @project, stringified_config: deep_encode(@hailstorm_config))
cluster_id = @hailstorm_config.clusters.first.title.to_java_string.hash_code
@browser.patch("/projects/#{@project.id}/clusters/#{cluster_id}", JSON.dump({ active: true }))
expect(@browser.last_response.status).to be == 200
project_config = ProjectConfiguration.first
hailstorm_config = deep_decode(project_config.stringified_config)
dc = hailstorm_config.clusters.first
expect(dc.active).to be true
end

context 'cluster is disabled' do
it 'should not update any field other than active' do
context 'any kind of cluster' do
before(:each) do
@hailstorm_config.clusters(:data_center) do |dc|
# @type [Hailstorm::Support::Configuration::DataCenter] dc
dc.title = 'Ice station Zebra'
Expand All @@ -417,9 +395,63 @@
end

ProjectConfiguration.create!(project: @project, stringified_config: deep_encode(@hailstorm_config))
cluster_id = @hailstorm_config.clusters.first.title.to_java_string.hash_code
@browser.patch("/projects/#{@project.id}/clusters/#{cluster_id}", JSON.dump({ user_name: 'root' }))
@cluster_id = @hailstorm_config.clusters.first.title.to_java_string.hash_code
end

it 'should be able to activate the cluster' do
@browser.patch("/projects/#{@project.id}/clusters/#{@cluster_id}", JSON.dump({ active: true }))
expect(@browser.last_response.status).to be == 200
project_config = ProjectConfiguration.first
hailstorm_config = deep_decode(project_config.stringified_config)
dc = hailstorm_config.clusters.first
expect(dc.active).to be true
end

it 'should be able to de-activate the cluster' do
@hailstorm_config.clusters.first.active = true
ProjectConfiguration.first.update_attributes!(stringified_config: deep_encode(@hailstorm_config))
@browser.patch("/projects/#{@project.id}/clusters/#{@cluster_id}", JSON.dump({ active: false }))
expect(@browser.last_response.status).to be == 200
project_config = ProjectConfiguration.first
hailstorm_config = deep_decode(project_config.stringified_config)
dc = hailstorm_config.clusters.first
expect(dc.active).to be false
end

context 'cluster is disabled' do
it 'should not update any field other than active' do
@browser.patch("/projects/#{@project.id}/clusters/#{@cluster_id}", JSON.dump({ user_name: 'root' }))
expect(@browser.last_response.status).to be == 422
end
end

it 'should not update cluster_code' do
@browser.patch("/projects/#{@project.id}/clusters/#{@cluster_id}", JSON.dump({ code: 'bot-cluster-200' }))
expect(@browser.last_response.status).to be == 422
project_config = ProjectConfiguration.first
hailstorm_config = deep_decode(project_config.stringified_config)
# @type [Hailstorm::Support::Configuration::DataCenter] dc
dc = hailstorm_config.clusters.first
expect(dc.cluster_code).to be == 'ice-station-zebra-119' # unchanged in the update
end

context 'project is running tests' do
it 'should not update any attribute' do
Hailstorm::Model::ExecutionCycle.create!(
project: @project,
status: Hailstorm::Model::ExecutionCycle::States::STARTED,
started_at: Time.now.ago(30.minutes),
threads_count: 100
)

@browser.patch("/projects/#{@project.id}/clusters/#{@cluster_id}", JSON.dump({ active: true }))
expect(@browser.last_response.status).to be == 422
project_config = ProjectConfiguration.first
hailstorm_config = deep_decode(project_config.stringified_config)
# @type [Hailstorm::Support::Configuration::DataCenter] dc
dc = hailstorm_config.clusters.first
expect(dc.active).to be_blank
end
end
end

Expand Down Expand Up @@ -462,5 +494,45 @@
end
end
end

context 'when DataCenter cluster' do
before(:each) do
@hailstorm_config.clusters(:data_center) do |dc|
# @type [Hailstorm::Support::Configuration::DataCenter] dc
dc.title = 'Bot cluster 2'
dc.user_name = 'root'
dc.ssh_identity = '123/foo.pem'
dc.machines = %w[172.16.0.10 172.16.0.20]
dc.ssh_port = 22
dc.cluster_code = 'bot-cluster-2'
end

ProjectConfiguration.create!(project: @project, stringified_config: deep_encode(@hailstorm_config))
@cluster_id = @hailstorm_config.clusters.first.title.to_java_string.hash_code
end

it 'should update all allowed attributes' do
request_params = {
title: 'Bot cluster 1',
userName: 'ubuntu',
sshIdentity: { name: 'secure.pem', path: '1234' },
sshPort: 8022,
machines: %w[172.16.0.10 172.16.0.20 172.16.0.30]
}

@browser.patch("/projects/#{@project.id}/clusters/#{@cluster_id}", JSON.dump(request_params))
expect(@browser.last_response.status).to be == 200
project_config = ProjectConfiguration.first
hailstorm_config = deep_decode(project_config.stringified_config)
# @type [Hailstorm::Support::Configuration::DataCenter] dc
dc = hailstorm_config.clusters.first
expect(dc.title).to be == request_params[:title]
expect(dc.user_name).to be == request_params[:userName]
expect(dc.ssh_identity).to be == "#{request_params[:sshIdentity][:path]}/#{request_params[:sshIdentity][:name]}"
expect(dc.machines).to be == request_params[:machines]
expect(dc.ssh_port).to be == request_params[:sshPort]
expect(dc.cluster_code).to be == 'bot-cluster-2' # unchanged in the update
end
end
end
end
2 changes: 1 addition & 1 deletion hailstorm-web-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hailstorm-web-client",
"version": "1.8.10",
"version": "1.9.10",
"private": true,
"dependencies": {
"date-fns": "^2.6.0",
Expand Down
5 changes: 3 additions & 2 deletions hailstorm-web-client/src/ClusterConfiguration/AWSForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { ErrorMessage, Field, Form, Formik } from 'formik';
import { Form, Formik } from 'formik';
import { AmazonCluster, Project } from '../domain';
import { FormikActionsHandler } from '../JMeterConfiguration/domain';
import { AWSFormField, AWSInstanceChoiceField } from './AWSFormField';
Expand All @@ -9,6 +9,7 @@ import { AWSInstanceChoiceOption, AWSRegionList } from './domain';
import { ReadOnlyField } from './ReadOnlyField';
import { MaxUsersByInstance } from './AWSInstanceChoice';
import { RemoveCluster } from './RemoveCluster';
import styles from '../NewProjectWizard/NewProjectWizard.module.scss';

export function AWSForm({
cluster,
Expand Down Expand Up @@ -60,7 +61,7 @@ export function AWSForm({
>
{({ isSubmitting, isValid, setFieldTouched, handleChange, values }) => (
<Form data-testid="AWSForm">
<div className="card-content">
<div className={`card-content${cluster && cluster.disabled ? ` ${styles.disabledContent}` : ''}`}>
<AWSFormField
labelText="AWS Access Key"
required={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { AWSInstanceChoiceOption, AWSRegionList } from './domain';
import { ClusterService } from "../services/ClusterService";
import { AWSRegionService } from "../services/AWSRegionService";
import { AWSEC2PricingService } from "../services/AWSEC2PricingService";
import { render as renderComponent, fireEvent, wait} from '@testing-library/react';
import { AmazonCluster, Cluster, DataCenterCluster, ExecutionCycleStatus } from '../domain';
import { render as renderComponent, fireEvent} from '@testing-library/react';
import { AmazonCluster, Cluster, DataCenterCluster } from '../domain';
import { ClusterSetupCompletedAction } from '../NewProjectWizard/actions';
import { RemoveClusterAction, ActivateClusterAction } from './actions';
import { AppNotificationContextProps } from '../app-notifications';
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('<ClusterConfiguration />', () => {
appState.wizardState!.activeCluster = {title: '', type: 'DataCenter'};
component.setProps({value: {appState, dispatch}});
component.update();
expect(component).toContainExactlyOneMatchingElement('DataCenterForm');
expect(component).toContainExactlyOneMatchingElement('NewDataCenter');
});
});

Expand Down Expand Up @@ -333,7 +333,7 @@ describe('<ClusterConfiguration />', () => {

it('should show DataCenterForm', () => {
const component = mount(createComponent());
expect(component).toContainExactlyOneMatchingElement('DataCenterForm');
expect(component).toContainExactlyOneMatchingElement('NewDataCenter');
});
});

Expand All @@ -353,7 +353,7 @@ describe('<ClusterConfiguration />', () => {

it('should show a created cluster', () => {
const component = mount(createComponent());
expect(component).toContainExactlyOneMatchingElement('DataCenterView');
expect(component).toContainExactlyOneMatchingElement('EditDataCenter');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { ClusterList } from '../ClusterList';
import { ActivateClusterAction, ChooseClusterOptionAction, SetClusterConfigurationAction } from './actions';
import { NewAWSCluster } from './NewAWSCluster';
import { EditAWSCluster } from './EditAWSCluster';
import { DataCenterForm } from './DataCenterForm';
import { DataCenterView } from './DataCenterView';
import { NewDataCenter } from './NewDataCenter';
import { EditDataCenter } from './EditDataCenter';
import { ApiFactory } from '../api';
import { Loader, LoaderSize } from '../Loader/Loader';

Expand Down Expand Up @@ -119,9 +119,9 @@ function StepContent({
/>)))}
{wizardState.activeCluster && wizardState.activeCluster.type === 'DataCenter' && (
(wizardState.activeCluster.id === undefined ? (
<DataCenterForm {...{dispatch, activeProject}} />
<NewDataCenter {...{dispatch, activeProject}} />
) : (
<DataCenterView
<EditDataCenter
cluster={wizardState.activeCluster! as DataCenterCluster}
{...{dispatch, activeProject}}
/>)))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Cluster, AmazonCluster, DataCenterCluster } from '../domain';
import { EditAWSCluster } from './EditAWSCluster';
import { DataCenterView } from './DataCenterView';
import { EditDataCenter } from './EditDataCenter';

export function ClusterDetailView({
cluster
Expand All @@ -14,7 +14,7 @@ export function ClusterDetailView({
}

if (cluster.type === 'DataCenter') {
return (<DataCenterView cluster={cluster as DataCenterCluster} />);
return (<EditDataCenter cluster={cluster as DataCenterCluster} />);
}

return null;
Expand Down
Loading

0 comments on commit ab42669

Please sign in to comment.