Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
feat(xdsl): add auto diagnostic routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérémy DE CESARE committed Aug 28, 2018
1 parent 236a89b commit 4360d0d
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 2 deletions.
82 changes: 82 additions & 0 deletions dist/ovh-api-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -21479,6 +21479,85 @@ angular.module("ovh-api-services").service("OvhApiXdslDeconsolidationV6", ["$res
);
}]);

angular.module("ovh-api-services").service("OvhApiXdslDiagnosticLines", ["$injector", "$cacheFactory", function ($injector, $cacheFactory) {
"use strict";

var cache = $cacheFactory("OvhApiXdslDiagnosticLines");

return {
v6: function () {
return $injector.get("OvhApiXdslDiagnosticLinesV6");
},
resetCache: cache.removeAll,
cache: cache
};
}]);

angular.module("ovh-api-services").service("OvhApiXdslDiagnosticLinesV6", ["$resource", "Poller", "OvhApiXdslDiagnosticLines", function ($resource, Poller, OvhApiXdslDiagnosticLines) {
"use strict";

var routes = {
base: "/xdsl/:serviceName/lines/:number/diagnostic",
cancel: "/xdsl/:serviceName/lines/:number/diagnostic/cancel",
run: "/xdsl/:serviceName/lines/:number/diagnostic/run"
};

var interceptor = function (response) {
OvhApiXdslDiagnosticLines.resetCache();
return response;
};

var diagnostic = $resource(routes.base, {
serviceName: "@serviceName",
number: "@number"
}, {
cancelDiagnostic: {
url: routes.cancel,
method: "POST",
isArray: false,
interceptor: interceptor
}
});

diagnostic.runDiagnostic = function (opts) {
var url = routes.run.replace(/\/:(\w*)\//g, function (match, replacement) {
return "/" + opts[replacement] + "/";
});

return Poller.poll(
url,
{
cache: false
},
{
method: "post",
postData: _.omit(opts, ["serviceName", "number"]),
interval: 30000,
successRule: function (response) {
if (response.status !== "problem") {
return true;
}

return _.isEqual(_.get(response, "data.error", ""), "monitoringTodoAlreadyExists");
},
errorRule: function (response) {
return _.isEqual(response.status, "problem") &&
!_.isEqual(_.get(response, "data.error", ""), "monitoringTodoAlreadyExists");
},
namespace: "xdsl_diagnostic_run"
}
);
};

diagnostic.killPollerDiagnostic = function () {
return Poller.kill({
namespace: "xdsl_diagnostic_run"
});
};

return diagnostic;
}]);

/* global angular*/
angular.module("ovh-api-services").service("OvhApiXdslDiagnosticAapi", ["$resource", "Poller", function ($resource, Poller) {
"use strict";
Expand Down Expand Up @@ -21533,6 +21612,9 @@ angular.module("ovh-api-services").service("OvhApiXdslDiagnostic", ["$injector",
Aapi: function () {
return $injector.get("OvhApiXdslDiagnosticAapi");
},
Lines: function () {
return $injector.get("OvhApiXdslDiagnosticLines");
},
resetCache: cache.removeAll,
cache: cache
};
Expand Down
4 changes: 2 additions & 2 deletions dist/ovh-api-services.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/xdsl/diagnostic/lines/xdsl-diagnostic-lines.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
angular.module("ovh-api-services").service("OvhApiXdslDiagnosticLines", function ($injector, $cacheFactory) {
"use strict";

var cache = $cacheFactory("OvhApiXdslDiagnosticLines");

return {
v6: function () {
return $injector.get("OvhApiXdslDiagnosticLinesV6");
},
resetCache: cache.removeAll,
cache: cache
};
});
66 changes: 66 additions & 0 deletions src/xdsl/diagnostic/lines/xdsl-diagnostic-lines.v6.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
angular.module("ovh-api-services").service("OvhApiXdslDiagnosticLinesV6", function ($resource, Poller, OvhApiXdslDiagnosticLines) {
"use strict";

var routes = {
base: "/xdsl/:serviceName/lines/:number/diagnostic",
cancel: "/xdsl/:serviceName/lines/:number/diagnostic/cancel",
run: "/xdsl/:serviceName/lines/:number/diagnostic/run"
};

var interceptor = function (response) {
OvhApiXdslDiagnosticLines.resetCache();
return response;
};

var diagnostic = $resource(routes.base, {
serviceName: "@serviceName",
number: "@number"
}, {
cancelDiagnostic: {
url: routes.cancel,
method: "POST",
isArray: false,
interceptor: interceptor
}
});

diagnostic.runDiagnostic = function (opts) {
// Replacement of each :myRouteParam by the corresponding json property
// (Example: :serviceName by opts.serviceName)
var url = routes.run.replace(/\/:(\w*)\//g, function (match, replacement) {
return "/" + opts[replacement] + "/";
});

return Poller.poll(
url,
{
cache: false
},
{
method: "post",
postData: _.omit(opts, ["serviceName", "number"]),
interval: 30000,
successRule: function (response) {
if (response.status !== "problem") {
return true;
}

return _.isEqual(_.get(response, "data.error", ""), "monitoringTodoAlreadyExists");
},
errorRule: function (response) {
return _.isEqual(response.status, "problem") &&
!_.isEqual(_.get(response, "data.error", ""), "monitoringTodoAlreadyExists");
},
namespace: "xdsl_diagnostic_run"
}
);
};

diagnostic.killPollerDiagnostic = function () {
return Poller.kill({
namespace: "xdsl_diagnostic_run"
});
};

return diagnostic;
});
3 changes: 3 additions & 0 deletions src/xdsl/diagnostic/xdsl-diagnostic.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ angular.module("ovh-api-services").service("OvhApiXdslDiagnostic", function ($in
Aapi: function () {
return $injector.get("OvhApiXdslDiagnosticAapi");
},
Lines: function () {
return $injector.get("OvhApiXdslDiagnosticLines");
},
resetCache: cache.removeAll,
cache: cache
};
Expand Down

0 comments on commit 4360d0d

Please sign in to comment.