### File

`src/app/instance/shared/instance.service.ts`

### Extends

`HelixService`

### Index

###### Methods
Public create Public disable Public enable Public get Public getAll Public remove Public can Protected delete Protected errorHandler Protected getHeaders Protected getHelixKey Protected post Protected put Protected request

### Methods

Public create
`create(clusterName: string, host: string, port: string, enabled: boolean)`
Defined in src/app/instance/shared/instance.service.ts:59
Parameters :
Name | Type | Optional
clusterName | `string` | No
host | `string` | No
port | `string` | No
enabled | `boolean` | No
Returns : `any`

Public disable
`disable(clusterName: string, instanceName: string)`
Defined in src/app/instance/shared/instance.service.ts:89
Parameters :
Name | Type | Optional
clusterName | `string` | No
instanceName | `string` | No
Returns : `any`

Public enable
`enable(clusterName: string, instanceName: string)`
Defined in src/app/instance/shared/instance.service.ts:82
Parameters :
Name | Type | Optional
clusterName | `string` | No
instanceName | `string` | No
Returns : `any`

Public get
`get(clusterName: string, instanceName: string)`
Defined in src/app/instance/shared/instance.service.ts:31
Parameters :
Name | Type | Optional
clusterName | `string` | No
instanceName | `string` | No
Returns : `any`

Public getAll
`getAll(clusterName: string)`
Defined in src/app/instance/shared/instance.service.ts:10
Parameters :
Name | Type | Optional
clusterName | `string` | No
Returns : `any`

Public remove
`remove(clusterName: string, instanceName: string)`
Defined in src/app/instance/shared/instance.service.ts:78
Parameters :
Name | Type | Optional
clusterName | `string` | No
instanceName | `string` | No
Returns : `any`

Public can
`can()`
Inherited from `HelixService`
Defined in `HelixService:14`
Returns : `Observable<any>`

Protected delete
`delete(path: string)`
Inherited from `HelixService`
Defined in `HelixService:48`
Parameters :
Name | Type | Optional
path | `string` | No
Returns : `Observable<any>`

Protected errorHandler
`errorHandler(error: any)`
Inherited from `HelixService`
Defined in `HelixService:68`
Parameters :
Name | Type | Optional
error | `any` | No
Returns : `any`

Protected getHeaders
`getHeaders()`
Inherited from `HelixService`
Defined in `HelixService:61`
Returns : `any`

Protected getHelixKey
`getHelixKey()`
Inherited from `HelixService`
Defined in `HelixService:56`
Returns : `string`

Protected post
`post(path: string, data: any)`
Inherited from `HelixService`
Defined in `HelixService:32`
Parameters :
Name | Type | Optional
path | `string` | No
data | `any` | No
Returns : `Observable<any>`

Protected put
`put(path: string, data: string)`
Inherited from `HelixService`
Defined in `HelixService:40`
Parameters :
Name | Type | Optional
path | `string` | No
data | `string` | No
Returns : `Observable<any>`

Protected request
`request(path: string, helix?: string)`
Inherited from `HelixService`
Defined in `HelixService:20`
Parameters :
Name | Type | Optional
path | `string` | No
helix | `string` | Yes
Returns : `Observable<any>`

    import { map } from 'rxjs/operators';
    import { Injectable } from '@angular/core';

    import { Instance } from './instance.model';
    import { HelixService } from '../../core/helix.service';
    import { Node } from '../../shared/models/node.model';

    @Injectable()
    export class InstanceService extends HelixService {
      public getAll(clusterName: string) {
        return this.request(`/clusters/${clusterName}/instances`).pipe(
          map((data) => {
            const onlineInstances = data.online;
            const disabledInstances = data.disabled;

            return data.instances
              .sort()
              .map(
                (name) =>
                  new Instance(
                    name,
                    clusterName,
                    disabledInstances.indexOf(name) < 0,
                    onlineInstances.indexOf(name) >= 0
                  )
              );
          })
        );
      }

      public get(clusterName: string, instanceName: string) {
        return this.request(
          `/clusters/${clusterName}/instances/${instanceName}`
        ).pipe(
          map((data) => {
            const liveInstance = data.liveInstance;
            const config = data.config;
            // there are two cases meaning enabled both:
            //   HELIX_ENABLED: true or no such configuration
            const enabled =
              config &&
              config.simpleFields &&
              config.simpleFields.HELIX_ENABLED != 'false';

            return liveInstance && liveInstance.simpleFields
              ? new Instance(
                  data.id,
                  clusterName,
                  enabled,
                  liveInstance.simpleFields.LIVE_INSTANCE,
                  liveInstance.simpleFields.SESSION_ID,
                  liveInstance.simpleFields.HELIX_VERSION
                )
              : new Instance(data.id, clusterName, enabled, null);
          })
        );
      }

      public create(
        clusterName: string,
        host: string,
        port: string,
        enabled: boolean
      ) {
        const name = `${host}_${port}`;

        const node = new Node(null);
        node.appendSimpleField('HELIX_ENABLED', enabled ? 'true' : 'false');
        node.appendSimpleField('HELIX_HOST', host);
        node.appendSimpleField('HELIX_PORT', port);

        return this.put(
          `/clusters/${clusterName}/instances/${name}`,
          JSON.parse(node.json(name))
        );
      }

      public remove(clusterName: string, instanceName: string) {
        return this.delete(`/clusters/${clusterName}/instances/${instanceName}`);
      }

      public enable(clusterName: string, instanceName: string) {
        return this.post(
          `/clusters/${clusterName}/instances/${instanceName}?command=enable`,
          null
        );
      }

      public disable(clusterName: string, instanceName: string) {
        return this.post(
          `/clusters/${clusterName}/instances/${instanceName}?command=disable`,
          null
        );
      }
    }

# results matching ""

# No results matching ""