def get():
    srv1 = 8658
    srv2 = 8659
    srv3 = 8660
    a1 = "Data dari"
    a2 = "adalah"
    if request.method == "GET":
        return render_template('1.html', server1 = srv1, server2 = srv2, server3 = srv3)
    elif request.method == "POST":
        select = request.form.get('field_id')
        if select == "8658":
            ipserver = "127.0.0.1:8658"
            d = DistributedDict('127.0.0.1',8658)
            nilai = d['key']
            return render_template('1.html',serverip = ipserver, server1 = srv1, server2 = srv2, server3 = srv3, test = nilai, act1 = a1, act2 = a2)
        elif select == "8659":
            ipserver = "127.0.0.1:8659"
            d = DistributedDict('127.0.0.1',8659)
            nilai = d['key']
            return render_template('1.html',serverip = ipserver, server1 = srv1, server2 = srv2, server3 = srv3, test = nilai,act1 = a1, act2 = a2)
        elif select == "8660":
            ipserver = "127.0.0.1:8660"
            d = DistributedDict('127.0.0.1',8660)
            nilai = d['key']
            return render_template('1.html',serverip = ipserver, server1 = srv1, server2 = srv2, server3 = srv3, test = nilai,act1 = a1, act2 = a2)
def index():
    if request.method == "GET":
        return render_template('index.html')
    elif request.method == "POST":
        try:
            data = request.form['inputan']
            d = DistributedDict('127.0.0.1',8658)
            d['key'] = data
            x = d['key']
            return render_template('index.html', nilai = x, aksi = "disetor ke", alamat = "127.0.0.1:8658")
        except:
            try:
                data = request.form['inputan']
                d = DistributedDict('127.0.0.1',8659)
                d['key'] = data
                x = d['key']
                return render_template('index.html', nilai = x, aksi = "disetor ke", alamat = "127.0.0.1:8659")
            except:
                try:
                    data = request.form['inputan']
                    d = DistributedDict('127.0.0.1',8660)
                    d['key'] = data
                    x = d['key']
                    return render_template('index.html', nilai = x, aksi = "disetor ke", alamat = "127.0.0.1:8660")
                except:
                    return render_template('errorhandle.html')
Beispiel #3
0
 def test_3_read_from_different_client(self):
     print('Read from different client')
     d = DistributedDict('127.0.0.1', 9110)
     d['adams'] = 'the hitchhiker guide'
     del d
     sleep(1)
     d = DistributedDict('127.0.0.1', 9111)
     self.assertEqual(d['adams'], 'the hitchhiker guide')
Beispiel #4
0
 def test_2_delete(self):
     print('Delete test')
     d = DistributedDict('127.0.0.1', 9110)
     d['adams'] = 'the hitchhiker guide'
     del d['adams']
     sleep(1)
     d = DistributedDict('127.0.0.1', 9110)
     self.assertEqual(d, {})
Beispiel #5
0
 def test_1_append(self):
     print('Append test')
     d = DistributedDict('127.0.0.1', 9110)
     d['adams'] = 'the hitchhiker guide'
     del d
     sleep(1)
     d = DistributedDict('127.0.0.1', 9110)
     self.assertEqual(d['adams'], 'the hitchhiker guide')
Beispiel #6
0
    def test_6_remove_server(self):
        print('Remove server')
        d = DistributedDict('127.0.0.1', 9110)
        d.config_cluster('delete', '127.0.0.1', 9111)
        sleep(1)

        self.pool.stop(1)

        self.assertEqual(set(map(tuple, d.diagnostic['volatile']['cluster'])),
                         {('127.0.0.1', 9112), ('127.0.0.1', 9110)})
Beispiel #7
0
 def test_2_delete(self):
     print('Delete test')
     d = DistributedDict('127.0.0.1', 9110, self.clusterMap,
                         self.privateKey)
     d['adams'] = 'the hitchhiker guide'
     sleep(1)
     del d['adams']
     sleep(1)
     d = DistributedDict('127.0.0.1', 9110, self.clusterMap,
                         self.privateKey)
     self.assertEqual(d, {'cluster': self.default_cluster})
Beispiel #8
0
 def test_append_read_different(self):
     print('Append test - Read Different')
     d = DistributedDict('127.0.0.1', 9116)
     d['adams'] = 'the hitchhiker guide'
     del d
     d = DistributedDict('127.0.0.1', 9117)
     self.assertEqual(d['adams'], 'the hitchhiker guide')
     del d
     d = DistributedDict('127.0.0.1', 9118)
     self.assertEqual(d['adams'], 'the hitchhiker guide')
     del d
Beispiel #9
0
 def test_4_compacted_log_replication(self):
     print('Compacted log replication')
     d = DistributedDict('127.0.0.1', 9110)
     d['test'] = 0
     d['test'] = 1
     d['test'] = 2
     d['test'] = 3
     d['test'] = 4  # compaction kicks in
     del d
     sleep(1)
     d = DistributedDict('127.0.0.1', 9111)
     self.assertEqual(d, {'test': 4})
Beispiel #10
0
 def test_append_write_multiple(self):
     print('Append test - Write Multiple')
     d0 = DistributedDict('127.0.0.1', 9116)
     d1 = DistributedDict('127.0.0.1', 9117)
     d2 = DistributedDict('127.0.0.1', 9118)
     d0['0'] = '0'
     d1['1'] = '1'
     d2['2'] = '2'
     self.assertEqual(d1['0'], '0')
     self.assertEqual(d2['1'], '1')
     self.assertEqual(d0['2'], '2')
     del d0
     del d1
     del d2
Beispiel #11
0
 def test_delete_complex(self):
     print('Delete test - Complex')
     d = DistributedDict('127.0.0.1', 9116)
     d['0'] = '0'
     d['1'] = '1'
     d['2'] = '2'
     d['3'] = '3'
     self.assertEqual(d['0'], '0')
     self.assertEqual(d['1'], '1')
     self.assertEqual(d['2'], '2')
     self.assertEqual(d['3'], '3')
     del d['0']
     self.assertEqual(d['0'], None)
     self.assertEqual(d['1'], '1')
     self.assertEqual(d['2'], '2')
     self.assertEqual(d['3'], '3')
     del d['3']
     del d['2']
     self.assertEqual(d['0'], None)
     self.assertEqual(d['1'], '1')
     self.assertEqual(d['2'], None)
     self.assertEqual(d['3'], None)
     d['2'] = '3'
     self.assertEqual(d['0'], None)
     self.assertEqual(d['1'], '1')
     self.assertEqual(d['2'], '3')
     self.assertEqual(d['3'], None)
     del d
Beispiel #12
0
 def test_delete_simple(self):
     print('Delete test - Simple')
     d = DistributedDict('127.0.0.1', 9116)
     d['adams'] = 'the hitchhiker guide'
     del d['adams']
     self.assertEqual(d['adams'], None)
     del d
Beispiel #13
0
    def test_0_diagnostics(self):
        print('Diagnostics test')
        print('Restarting server 0 to force Follower state')
        self.pool.stop(0)
        # sleep(2)
        self.pool.start(0)
        sleep(2)
        expected =\
            {'files': 'STUB', 'status': 'Follower',
             'persist': {'votedFor': 'STUB', 'currentTerm': 'STUB'},
             'volatile': {'leaderId': 'STUB', 'address': ['127.0.0.1', 9110],
                          'cluster': set((('127.0.0.1', 9112),
                                          ('127.0.0.1', 9110),
                                          ('127.0.0.1', 9111)))},
             'log': {'commitIndex': -1, 'log': {'data': [], 'path': 'STUB'},
                     'state_machine': {'lastApplied': -1, 'data': {}},
                     'compacted': {'count': 0, 'term': None, 'path': 'STUB',
                                   'data': {}}}}

        d = DistributedDict('127.0.0.1', 9110)
        diagnostics = d.diagnostic
        diagnostics['files'] = 'STUB'
        diagnostics['log']['compacted']['path'] = 'STUB'
        diagnostics['log']['log']['path'] = 'STUB'
        diagnostics['persist']['votedFor'] = 'STUB'
        diagnostics['persist']['currentTerm'] = 'STUB'
        diagnostics['volatile']['leaderId'] = 'STUB'
        diagnostics['volatile']['cluster'] =\
            set(map(tuple, diagnostics['volatile']['cluster']))
        self.assertEqual(expected, diagnostics)
Beispiel #14
0
 def test_append_write_failure_complex(self):
     print('Append test - Write Failure Complex')
     d = DistributedDict('127.0.0.1', 9116)
     d['adams'] = 'the hitchhiker guide'
     self.pool.stop(0)
     self.assertEqual(d['adams'], 'the hitchhiker guide')
     del d['adams']
     self.pool.start(0)
     self.pool.stop(1)
     d['foo'] = 'bar'
     self.assertEqual(d['adams'], None)
     self.assertEqual(d['foo'], 'bar')
     self.pool.start(1)
     self.pool.stop(2)
     d['bar'] = 'foo'
     del d['foo']
     self.assertEqual(d['adams'], None)
     self.assertEqual(d['foo'], None)
     self.assertEqual(d['bar'], 'foo')
     del d['bar']
     self.pool.start(2)
     self.pool.stop(0)
     d['1'] = '0'
     self.assertEqual(d['adams'], None)
     self.assertEqual(d['foo'], None)
     self.assertEqual(d['bar'], None)
     self.assertEqual(d['1'], '0')
     self.pool.start(0)
     del d
Beispiel #15
0
    def test_5_add_server(self):
        print('Add new server')
        d = DistributedDict('127.0.0.1', 9110)
        d['test'] = 0
        self.pool.stop(self.pool.ids)
        self.pool.start(self.pool.ids)

        self.pool.configs[10] = {
            'address': ('127.0.0.1', 9120),
            'cluster': {
                ('127.0.0.1', 9120),
            },
            'storage': '20.persist',
            'debug': False
        }
        self.pool.servers[10] = Process(target=self.pool._run_server,
                                        args=(self.pool.configs[10], ))
        self.pool.start(10)
        sleep(1)

        d.config_cluster('add', '127.0.0.1', 9120)
        sleep(1)

        del d
        d = DistributedDict('127.0.0.1', 9120)

        self.assertEqual(d, {'test': 0})
Beispiel #16
0
 def test_append_write_failure_simple(self):
     print('Append test - Write Failure Simple')
     d = DistributedDict('127.0.0.1', 9116)
     d['adams'] = 'the hitchhiker guide'
     self.pool.stop(0)
     self.assertEqual(d['adams'], 'the hitchhiker guide')
     self.pool.start(0)
     self.pool.stop(1)
     d['0'] = '1'
     self.assertEqual(d['adams'], 'the hitchhiker guide')
     self.pool.start(1)
     self.pool.stop(2)
     d['1'] = '0'
     self.assertEqual(d['adams'], 'the hitchhiker guide')
     del d
Beispiel #17
0
from zatt.client import DistributedDict

d = DistributedDict('127.0.0.1', 5254)
d['key1'] = 0
Beispiel #18
0
from zatt.client import DistributedDict
import time

starttime = time.time()
d = DistributedDict('127.0.0.1', 8660)
print('port: 8660')
print(d['key'])
endtime = time.time()
print(endtime - starttime)
Beispiel #19
0
 def __init__(self, port):
     self.data = DistributedDict('127.0.0.1', port)
Beispiel #20
0
class CRUD_Distributed():
    def __init__(self, port):
        self.data = DistributedDict('127.0.0.1', port)

    def set_patient(self, idPatient, nameRN, motherRN, birth, sex, age,
                    doctor):
        # if not b_any(f'doctor:{doctor.lower()}' in x.lower() for x in self.data):
        #     return 'Doctor is not registered.'

        if f'Patient:{idPatient}' in self.data:
            return "Patient already exists."
        else:

            self.data[f'Patient:{idPatient}'] = dict_to_string({
                "nameNB": nameRN,
                "MotherName": motherRN,
                "Birth": birth,
                "Sex": sex,
                "Age": age,
                "Doctor": doctor,
                "Procedure": []
            })
            return "New patient succesfully inserted."

    def get_patient(self, idPatient):
        if f'Patient:{idPatient}' in [*self.data.keys()]:
            return self.data[f'Patient:{idPatient}']
        else:
            return None

    def delete_patient(self, idPatient):
        if f'Patient:{idPatient}' in [*self.data.keys()]:
            del self.data[f'Patient:{idPatient}']
            return "Patient succesfully deleted."
        else:
            return "Patient not found."

    def list_patients(self):
        patient = []
        keys_ = [*self.data.keys()]
        for key in keys_:
            if (key != 'cluster') and ('patient' in key.lower()):
                patient.append([key.split(':')[1], self.data[key]])
        return patient

    def get_procedure(self, idPatient):
        if f'Patient:{idPatient}' in [*self.data.keys()]:
            patient = string_to_dict(self.data[f'Patient:{idPatient}'])
            patient = string_to_dict(patient)
            if len(patient['Procedure']) > 0:
                return patient['Procedure']
            else:
                return None
        else:
            return "Patient not found."

    def set_procedure(self, idPatient, idProcedure, date, description):
        if f'Patient:{idPatient}' in [*self.data.keys()]:
            patient_data = self.data[f'Patient:{idPatient}']
            patient_data = string_to_dict(patient_data)

            patient_data['Procedure'].append({
                'idProcedure': idProcedure,
                'description': description,
                'date': date
            })

            self.data[f'Patient:{idPatient}'] = dict_to_string(patient_data)
            return "New procedure succesfully inserted."
        else:
            return "Patient not found."

    def set_doctor(self, CRM, name, birth):
        if f'Doctor:{CRM}' in self.data:
            return "Doctor already exists."
        else:
            self.data[f'Doctor:{CRM}'] = dict_to_string({
                "name": name,
                "birth": birth
            })
            return "New doctor succefully inserted."

    def get_doctor(self, CRM):
        if f'Doctor:{CRM}' in [*self.data.keys()]:
            return self.data[f'Doctor:{CRM}']
        else:
            return None

    def list_doctors(self):
        doctors = []
        keys_ = [*self.data.keys()]
        for key in keys_:
            if (key != 'cluster') and ('doctor' in key.lower()):
                doctors.append([key.split(':')[1], self.data[key]])
        return doctors

    def list_all_patients_doctor(self, CRM):
        CRM = CRM[0:-1]
        all_patients = []
        for key, value in self.data.items():
            if CRM in value:
                all_patients.append([key.split(':')[1], self.data[key]])
        return all_patients

    def is_doctor_register(self, CRM):
        if f'Doctor:{CRM}' in [*self.data.keys()]:
            return 'yes'
        else:
            return 'no'


# c = Clusters_Servers()
# print(c.split())
Beispiel #21
0
from flask import Flask, request
from zatt.client import DistributedDict
from json import dumps
import time

app = Flask(__name__)

leader = DistributedDict('127.0.0.1', 5254)
fol1 = DistributedDict('127.0.0.1', 5255)
fol2 = DistributedDict('127.0.0.1', 5256)


@app.route('/showleader', methods=['GET'])
def show():
    return dumps(leader['key1'])


@app.route('/showfollower1', methods=['GET'])
def show1():
    return dumps(fol1['key1'])


@app.route('/showfollower2', methods=['GET'])
def show2():
    return dumps(fol2['key1'])


@app.route('/set/<arg>', methods=['POST'])
def set(arg):
    leader['key1'] = arg
    return dumps('Berhasil')
Beispiel #22
0
 def test_append_read_same(self):
     print('Append test - Read Same')
     d = DistributedDict('127.0.0.1', 9116)
     d['adams'] = 'the hitchhiker guide'
     self.assertEqual(d['adams'], 'the hitchhiker guide')
     del d