sqoop.connectors.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. var connectors = (function($) {
  17. var CONNECTOR_NAMES = ["hdfs-connector", "generic-jdbc-connector"];
  18. var ConnectorModel = koify.Model.extend({
  19. 'id': -1,
  20. 'name': null,
  21. 'class': null,
  22. 'job_config': {
  23. 'FROM': [],
  24. 'TO': []
  25. },
  26. 'link_config': [],
  27. 'version': null,
  28. 'config_resources': {},
  29. 'initialize': function(attrs) {
  30. var self = this;
  31. var _attrs = $.extend(true, {}, attrs);
  32. _attrs = transform_keys(_attrs, {
  33. 'link_config': 'link_config',
  34. 'job_config': 'job_config'
  35. });
  36. _attrs = transform_values(_attrs, {
  37. 'link_config': to_configs,
  38. 'job_config': function(key, value) {
  39. transform_values(value, {
  40. 'FROM': to_configs,
  41. 'TO': to_configs
  42. });
  43. return value;
  44. }
  45. });
  46. return _attrs;
  47. }
  48. });
  49. var Connector = koify.Node.extend({
  50. 'identifier': 'connector',
  51. 'persist': false,
  52. 'model_class': ConnectorModel,
  53. 'base_url': '/sqoop/api/connectors/',
  54. 'initialize': function() {
  55. var self = this;
  56. self.parent.initialize.apply(self, arguments);
  57. self.selected = ko.observable();
  58. },
  59. map: function() {
  60. var self = this;
  61. var mapping_options = $.extend(true, {
  62. 'ignore': ['parent', 'initialize']
  63. }, configs.MapProperties);
  64. if ('__ko_mapping__' in self) {
  65. ko.mapping.fromJS(self.model, mapping_options, self);
  66. } else {
  67. var mapped = ko.mapping.fromJS(self.model, mapping_options);
  68. $.extend(self, mapped);
  69. }
  70. }
  71. });
  72. function fetch_connectors(options) {
  73. $(document).trigger('load.connectors', [options]);
  74. var request = $.extend({
  75. url: '/sqoop/api/connectors/',
  76. dataType: 'json',
  77. type: 'GET',
  78. success: fetcher_success('connectors', Connector, options),
  79. error: fetcher_error('connectors', Connector, options)
  80. }, options || {});
  81. $.ajax(request);
  82. }
  83. return {
  84. 'ConnectorModel': ConnectorModel,
  85. 'Connector': Connector,
  86. 'fetchConnectors': fetch_connectors,
  87. 'CONNECTOR_NAMES': CONNECTOR_NAMES
  88. };
  89. })($);