RackHD/on-http

View on GitHub
lib/services/nodes-api-service.js

Summary

Maintainability
F
1 wk
Test Coverage

Function nodeApiServiceFactory has 544 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function nodeApiServiceFactory(
    workflowApiService,
    waterline,
    Errors,
    Logger,
Severity: Major
Found in lib/services/nodes-api-service.js - About 2 days to fix

    Function nodeApiServiceFactory has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
    Open

    function nodeApiServiceFactory(
        workflowApiService,
        waterline,
        Errors,
        Logger,
    Severity: Minor
    Found in lib/services/nodes-api-service.js - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File nodes-api-service.js has 579 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    // Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.
    
    'use strict';
    
    var di = require('di');
    Severity: Major
    Found in lib/services/nodes-api-service.js - About 1 day to fix

      Function postNode has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          NodeApiService.prototype.postNode = function(body) {
              var nodeBody = _.omit(body, ['obms', 'ibms']);
              var obmBody = body.obms || body.obmSettings || null;
              var ibmBody = body.ibms || null;
      
      
      Severity: Major
      Found in lib/services/nodes-api-service.js - About 2 hrs to fix

        Function addRelation has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            NodeApiService.prototype.addRelation = function addRelation(node, type, targets) {
                if (!(node && type && targets)) {
                    return;
                }
                return waterline.nodes.addFieldIfNotExistByIdentifier(node.id, "relations", [])
        Severity: Major
        Found in lib/services/nodes-api-service.js - About 2 hrs to fix

          Function removeNode has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              NodeApiService.prototype.removeNode = function(node, srcType) {
                  var self = this;
                  return self._delValidityCheck(node.id)
                  .then(function () {
                      if (!node.hasOwnProperty('relations')) {
          Severity: Major
          Found in lib/services/nodes-api-service.js - About 2 hrs to fix

            Function nodeApiServiceFactory has 12 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                workflowApiService,
                waterline,
                Errors,
                Logger,
                _,
            Severity: Major
            Found in lib/services/nodes-api-service.js - About 1 hr to fix

              Function editNodeRelations has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  NodeApiService.prototype.editNodeRelations = function(id, body, handler) {
                      var self = this;
                      return waterline.nodes.needByIdentifier(id).bind({})
                      .then(function(node) {
                          this.parentNode = node;
              Severity: Minor
              Found in lib/services/nodes-api-service.js - About 1 hr to fix

                Avoid too many return statements within this function.
                Open

                        return waterline.nodes.removeListItemsByIdentifier(node.id, targetsToBeRemoved)
                        .then(function(modifiedNode){
                            return self.removeRelation(modifiedNode, type);
                        });
                Severity: Major
                Found in lib/services/nodes-api-service.js - About 30 mins to fix

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      NodeApiService.prototype.putObmsByNodeId = function(id, obm) {
                          return waterline.nodes.getNodeById(id)
                              .then(function (node) {
                                  if (!node) {
                                      throw new Errors.NotFoundError(
                  Severity: Major
                  Found in lib/services/nodes-api-service.js and 1 other location - About 2 hrs to fix
                  lib/services/nodes-api-service.js on lines 498..508

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 90.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      NodeApiService.prototype.postNodeSshById = function(id, ibm) {
                          return waterline.nodes.getNodeById(id)
                              .then(function (node) {
                                  if (!node) {
                                      throw new Errors.NotFoundError(
                  Severity: Major
                  Found in lib/services/nodes-api-service.js and 1 other location - About 2 hrs to fix
                  lib/services/nodes-api-service.js on lines 739..749

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 90.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                          return Promise.resolve().then(function() {
                              assert.string(tagName, 'tag must be a string');
                          })
                          .then(function() {
                              return waterline.nodes.findByTag(tagName);
                  Severity: Major
                  Found in lib/services/nodes-api-service.js and 1 other location - About 1 hr to fix
                  lib/services/nodes-api-service.js on lines 690..699

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 66.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                          return Promise.resolve().then(function() {
                              assert.isMongoId(id, 'the id must be a valid mongo id');
                          })
                          .then(function() {
                              return waterline.nodes.needByIdentifier(id);
                  Severity: Major
                  Found in lib/services/nodes-api-service.js and 1 other location - About 1 hr to fix
                  lib/services/nodes-api-service.js on lines 663..674

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 66.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                              else if(node.type === Constants.NodeTypes.Pdu &&
                                      snmpSettings && node.autoDiscover) {
                                  return workflowApiService.createAndRunGraph(
                                      {
                                          name: 'Graph.PDU.Discovery',
                  Severity: Major
                  Found in lib/services/nodes-api-service.js and 1 other location - About 1 hr to fix
                  lib/services/nodes-api-service.js on lines 333..371

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 56.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                              if(node.type === Constants.NodeTypes.Switch &&
                                 snmpSettings && node.autoDiscover) {
                                  return workflowApiService.createAndRunGraph(
                                      {
                                          name: 'Graph.Switch.Discovery',
                  Severity: Major
                  Found in lib/services/nodes-api-service.js and 1 other location - About 1 hr to fix
                  lib/services/nodes-api-service.js on lines 345..371

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 56.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                          return Promise.resolve()
                          .then(function() {
                              return waterline.nodes.create(nodeBody);
                          }).tap(function(node) {
                              return eventsProtocol.publishNodeEvent(node, 'added');
                  Severity: Minor
                  Found in lib/services/nodes-api-service.js and 1 other location - About 55 mins to fix
                  lib/services/nodes-api-service.js on lines 313..330

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 53.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                                      return waterline.catalogs.findLatestCatalogOfSource(
                                          node.id, source
                                      ).then(function (catalogs) {
                                          if (_.isEmpty(catalogs)) {
                                              throw new Errors.NotFoundError(
                  Severity: Minor
                  Found in lib/services/nodes-api-service.js and 1 other location - About 30 mins to fix
                  lib/services/nodes-api-service.js on lines 663..674

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 45.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status