Java Code Examples for org.apache.sqoop.model.MLink#setPersistenceId()
The following examples show how to use
org.apache.sqoop.model.MLink#setPersistenceId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJobManager.java From sqoop-on-spark with Apache License 2.0 | 6 votes |
@Test public void testDisabledLink() { MLink testConnection = new MLink(123l, null); testConnection.setPersistenceId(1234); testConnection.setEnabled(false); SqoopException exception = new SqoopException(DriverError.DRIVER_0010, "Connection id: " + testConnection.getPersistenceId()); MLink mConnectionSpy = org.mockito.Mockito.spy(testConnection); when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock); when(jdbcRepoMock.findLink(123l)).thenReturn(mConnectionSpy); try { jobManager.getLink(123l); } catch (SqoopException ex) { assertEquals(ex.getMessage(), exception.getMessage()); verify(repositoryManagerMock, times(1)).getRepository(); verify(jdbcRepoMock, times(1)).findLink(123l); } }
Example 2
Source File: TestLinkHandling.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = SqoopException.class) public void testCreateDuplicateLink() throws Exception { MLink link = getLink(); fillLink(link); link.setName("test"); handler.createLink(link, getDerbyDatabaseConnection()); assertEquals(1, link.getPersistenceId()); link.setPersistenceId(MLink.PERSISTANCE_ID_DEFAULT); handler.createLink(link, getDerbyDatabaseConnection()); }
Example 3
Source File: LinkBean.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
private MLink restoreLink(Object obj) { JSONObject object = (JSONObject) obj; long connectorId = (Long) object.get(CONNECTOR_ID); JSONArray connectorLinkConfig = (JSONArray) object.get(LINK_CONFIG_VALUES); List<MConfig> linkConfig = restoreConfigList(connectorLinkConfig); MLink link = new MLink(connectorId, new MLinkConfig(linkConfig)); link.setPersistenceId((Long) object.get(ID)); link.setName((String) object.get(NAME)); link.setEnabled((Boolean) object.get(ENABLED)); link.setCreationUser((String) object.get(CREATION_USER)); link.setCreationDate(new Date((Long) object.get(CREATION_DATE))); link.setLastUpdateUser((String) object.get(UPDATE_USER)); link.setLastUpdateDate(new Date((Long) object.get(UPDATE_DATE))); return link; }
Example 4
Source File: BeanTestUtil.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
public static MLink createLink(String connectorName, String linkName, Long linkId, Date created, Date updated) { MLink link1 = getLink(connectorName); link1.setName(linkName); link1.setPersistenceId(linkId); link1.setCreationUser("admin"); link1.setCreationDate(created); link1.setLastUpdateUser("user"); link1.setLastUpdateDate(updated); link1.setEnabled(false); return link1; }
Example 5
Source File: TestLinkHandling.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
@Test(expectedExceptions = SqoopException.class) public void testCreateDuplicateLink() throws Exception { MLink link = handler.findLink(LINK_A_NAME, provider.getConnection()); link.setPersistenceId(MLink.PERSISTANCE_ID_DEFAULT); handler.createLink(link, provider.getConnection()); }
Example 6
Source File: CommonRepositoryHandler.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void createLink(MLink link, Connection conn) { PreparedStatement stmt = null; int result; try { stmt = conn.prepareStatement(crudQueries.getStmtInsertLink(), Statement.RETURN_GENERATED_KEYS); stmt.setString(1, link.getName()); stmt.setLong(2, link.getConnectorId()); stmt.setBoolean(3, link.getEnabled()); stmt.setString(4, link.getCreationUser()); stmt.setTimestamp(5, new Timestamp(link.getCreationDate().getTime())); stmt.setString(6, link.getLastUpdateUser()); stmt.setTimestamp(7, new Timestamp(link.getLastUpdateDate().getTime())); result = stmt.executeUpdate(); if (result != 1) { throw new SqoopException(CommonRepositoryError.COMMON_0009, Integer.toString(result)); } ResultSet rsetConnectionId = stmt.getGeneratedKeys(); if (!rsetConnectionId.next()) { throw new SqoopException(CommonRepositoryError.COMMON_0010); } long connectionId = rsetConnectionId.getLong(1); createInputValues( crudQueries.getStmtInsertLinkInput(), connectionId, link.getConnectorLinkConfig().getConfigs(), conn); link.setPersistenceId(connectionId); } catch (SQLException ex) { logException(ex, link); throw new SqoopException(CommonRepositoryError.COMMON_0016, ex); } finally { closeStatements(stmt); } }
Example 7
Source File: CommonRepositoryHandler.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
private List<MLink> loadLinks(PreparedStatement stmt, Connection conn) throws SQLException { List<MLink> links = new ArrayList<MLink>(); ResultSet rsConnection = null; PreparedStatement connectorConfigFetchStatement = null; PreparedStatement connectorConfigInputStatement = null; try { rsConnection = stmt.executeQuery(); connectorConfigFetchStatement = conn.prepareStatement(crudQueries.getStmtSelectConfigForConfigurable()); connectorConfigInputStatement = conn.prepareStatement(crudQueries.getStmtFetchLinkInput()); while(rsConnection.next()) { long id = rsConnection.getLong(1); String name = rsConnection.getString(2); long connectorId = rsConnection.getLong(3); boolean enabled = rsConnection.getBoolean(4); String creationUser = rsConnection.getString(5); Date creationDate = rsConnection.getTimestamp(6); String updateUser = rsConnection.getString(7); Date lastUpdateDate = rsConnection.getTimestamp(8); connectorConfigFetchStatement.setLong(1, connectorId); connectorConfigInputStatement.setLong(1, id); connectorConfigInputStatement.setLong(3, id); List<MConfig> connectorLinkConfig = new ArrayList<MConfig>(); List<MConfig> fromConfig = new ArrayList<MConfig>(); List<MConfig> toConfig = new ArrayList<MConfig>(); loadConnectorConfigs(connectorLinkConfig, fromConfig, toConfig, connectorConfigFetchStatement, connectorConfigInputStatement, 2, conn); MLink link = new MLink(connectorId, new MLinkConfig(connectorLinkConfig)); link.setPersistenceId(id); link.setName(name); link.setCreationUser(creationUser); link.setCreationDate(creationDate); link.setLastUpdateUser(updateUser); link.setLastUpdateDate(lastUpdateDate); link.setEnabled(enabled); links.add(link); } } finally { closeResultSets(rsConnection); closeStatements(connectorConfigFetchStatement, connectorConfigInputStatement); } return links; }
Example 8
Source File: LinkRequestHandler.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
/** * Create or Update link in repository. * * @param ctx Context object * @return Validation bean object */ private JsonBean createUpdateLink(RequestContext ctx, boolean create) { Repository repository = RepositoryManager.getInstance().getRepository(); LinkBean linkBean = new LinkBean(); try { JSONObject postData = JSONUtils.parse(ctx.getRequest().getReader()); linkBean.restore(postData); } catch (IOException e) { throw new SqoopException(ServerError.SERVER_0003, "Can't read request content", e); } String username = ctx.getUserName(); // Get link object List<MLink> links = linkBean.getLinks(); if (links.size() != 1) { throw new SqoopException(ServerError.SERVER_0003, "Expected one link while parsing JSON request but got " + links.size()); } MLink postedLink = links.get(0); // Authorization check if (create) { AuthorizationEngine.createLink(String.valueOf(postedLink.getConnectorId())); } else { AuthorizationEngine.updateLink(String.valueOf(postedLink.getConnectorId()), String.valueOf(postedLink.getPersistenceId())); } MLinkConfig linkConfig = ConnectorManager.getInstance() .getConnectorConfigurable(postedLink.getConnectorId()).getLinkConfig(); if (!linkConfig.equals(postedLink.getConnectorLinkConfig())) { throw new SqoopException(ServerError.SERVER_0003, "Detected incorrect link config structure"); } // if update get the link id from the request URI if (!create) { String linkIdentifier = ctx.getLastURLElement(); // support linkName or linkId for the api long linkId = HandlerUtils.getLinkIdFromIdentifier(linkIdentifier, repository); if (postedLink.getPersistenceId() == MPersistableEntity.PERSISTANCE_ID_DEFAULT) { MLink existingLink = repository.findLink(linkId); postedLink.setPersistenceId(existingLink.getPersistenceId()); } } // Associated connector for this link SqoopConnector connector = ConnectorManager.getInstance().getSqoopConnector( postedLink.getConnectorId()); // Validate user supplied config data ConfigValidationResult connectorLinkConfigValidation = ConfigUtils.validateConfigs(postedLink .getConnectorLinkConfig().getConfigs(), connector.getLinkConfigurationClass()); // Return back link validation result bean ValidationResultBean linkValidationBean = new ValidationResultBean( connectorLinkConfigValidation); // If we're good enough let's perform the action if (connectorLinkConfigValidation.getStatus().canProceed()) { if (create) { AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(), "create", "link", String.valueOf(postedLink.getPersistenceId())); postedLink.setCreationUser(username); postedLink.setLastUpdateUser(username); repository.createLink(postedLink); linkValidationBean.setId(postedLink.getPersistenceId()); } else { AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(), ctx.getRequest().getRemoteAddr(), "update", "link", String.valueOf(postedLink.getPersistenceId())); postedLink.setLastUpdateUser(username); repository.updateLink(postedLink); } } return linkValidationBean; }
Example 9
Source File: CloneLinkFunction.java From sqoop-on-spark with Apache License 2.0 | 4 votes |
private Status cloneLink(Long connectionId, List<String> args, boolean isInteractive) throws IOException { printlnResource(Constants.RES_CLONE_CLONING_LINK, connectionId); ConsoleReader reader = new ConsoleReader(); MLink connection = client.getLink(connectionId); // Remove persistent id as we're making a clone connection.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT); Status status = Status.OK; ResourceBundle linkConfigBundle = client.getConnectorConfigBundle(connection.getConnectorId()); if (isInteractive) { printlnResource(Constants.RES_PROMPT_UPDATE_LINK_CONFIG); do { // Print error introduction if needed if( !status.canProceed() ) { errorIntroduction(); } // Fill in data from user if(!fillLinkWithBundle(reader, connection, linkConfigBundle)) { return null; } status = client.saveLink(connection); } while(!status.canProceed()); } else { LinkDynamicConfigOptions options = new LinkDynamicConfigOptions(); options.prepareOptions(connection); CommandLine line = ConfigOptions.parseOptions(options, 0, args, false); if (fillLink(line, connection)) { status = client.saveLink(connection); if (!status.canProceed()) { printLinkValidationMessages(connection); return null; } } else { printLinkValidationMessages(connection); return null; } } printlnResource(Constants.RES_CLONE_LINK_SUCCESSFUL, status.name(), connection.getPersistenceId()); return status; }