001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008-2009 Sun Microsystems, Inc.
015 * Portions Copyright 2015-2016 ForgeRock AS.
016 */
017package org.opends.server.tools.dsreplication;
018
019import org.opends.server.types.HostPort;
020
021/**
022 * This class is used to store the information provided by the user to enable
023 * replication.  It is required because when we are in interactive mode the
024 * ReplicationCliArgumentParser is not enough.
025 */
026public class EnableReplicationUserData extends ReplicationUserData
027{
028  /** Data for enabling replication on a server. */
029  static final class EnableReplicationServerData
030  {
031    private HostPort hostPort = new HostPort(null, 0);
032    private String bindDn;
033    private String pwd;
034    private int replicationPort;
035    private boolean secureReplication;
036    private boolean configureReplicationServer = true;
037    private boolean configureReplicationDomain = true;
038
039    /**
040     * Returns the host name and port of this server.
041     *
042     * @return the host name and port of this server.
043     */
044    HostPort getHostPort()
045    {
046      return hostPort;
047    }
048
049    /**
050     * Sets the host name and port of this server.
051     *
052     * @param hostPort
053     *          the host name and port of this server
054     */
055    void setHostPort(HostPort hostPort)
056    {
057      this.hostPort = hostPort;
058    }
059
060    /**
061     * Returns the host name of this server.
062     *
063     * @return the host name of this server.
064     */
065    String getHostName()
066    {
067      return hostPort.getHost();
068    }
069
070    /**
071     * Returns the port of this server.
072     *
073     * @return the port of this server
074     */
075    int getPort()
076    {
077      return hostPort.getPort();
078    }
079
080    /**
081     * Returns the password for this server.
082     *
083     * @return the password for this server
084     */
085    String getPwd()
086    {
087      return pwd;
088    }
089
090    /**
091     * Sets the password for this server.
092     *
093     * @param pwd
094     *          the password for this server
095     */
096    void setPwd(String pwd)
097    {
098      this.pwd = pwd;
099    }
100
101    /**
102     * Returns the dn to be used to bind to this server.
103     *
104     * @return the dn to be used to bind to this server
105     */
106    String getBindDn()
107    {
108      return bindDn;
109    }
110
111    /**
112     * Sets the dn to be used to bind to this server.
113     *
114     * @param bindDn
115     *          the dn to be used to bind to this server
116     */
117    void setBindDn(String bindDn)
118    {
119      this.bindDn = bindDn;
120    }
121
122    /**
123     * Returns the replication port to be used on this server if it is not defined yet.
124     *
125     * @return the replication port to be used on this server if it is not defined yet
126     */
127    int getReplicationPort()
128    {
129      return replicationPort;
130    }
131
132    /**
133     * Sets the replication port to be used on this server if it is not defined yet.
134     *
135     * @param replicationPort
136     *          the replication port to be used on this server if it is not defined yet.
137     */
138    void setReplicationPort(int replicationPort)
139    {
140      this.replicationPort = replicationPort;
141    }
142
143    /**
144     * Returns whether the user asked to have secure replication communication with this server.
145     *
146     * @return {@code true} if the user asked to have secure replication communication with the
147     *         second server, {@code false} otherwise.
148     */
149    boolean isSecureReplication()
150    {
151      return secureReplication;
152    }
153
154    /**
155     * Sets whether to use secure replication communication with this server.
156     *
157     * @param secureReplication
158     *          whether to use secure replication communication with this server .
159     */
160    void setSecureReplication(boolean secureReplication)
161    {
162      this.secureReplication = secureReplication;
163    }
164
165    /**
166     * Returns whether the user asked to configure the replication server on this server.
167     *
168     * @return whether the user asked to configure the replication server on this server
169     */
170    boolean configureReplicationServer()
171    {
172      return configureReplicationServer;
173    }
174
175    /**
176     * Sets whether to configure the replication server on this server.
177     *
178     * @param configureReplicationServer
179     *          whether to configure the replication server on this server
180     */
181    void setConfigureReplicationServer(boolean configureReplicationServer)
182    {
183      this.configureReplicationServer = configureReplicationServer;
184    }
185
186    /**
187     * Returns whether the user asked to configure the replication domain on this server.
188     *
189     * @return whether the user asked to configure the replication domain on this server
190     */
191    boolean configureReplicationDomain()
192    {
193      return configureReplicationDomain;
194    }
195
196    /**
197     * Sets whether to configure the replication domain on this server.
198     *
199     * @param configureReplicationDomain
200     *          whether to configure the replication domain on this server
201     */
202    void setConfigureReplicationDomain(boolean configureReplicationDomain)
203    {
204      this.configureReplicationDomain = configureReplicationDomain;
205    }
206  }
207
208  private EnableReplicationServerData server1 = new EnableReplicationServerData();
209  private EnableReplicationServerData server2 = new EnableReplicationServerData();
210  private boolean replicateSchema = true;
211
212  /**
213   * Returns <CODE>true</CODE> if the user asked to replicate schema and <CODE>
214   * false</CODE> otherwise.
215   * @return <CODE>true</CODE> if the user asked to replicate schema and <CODE>
216   * false</CODE> otherwise.
217   */
218  public boolean replicateSchema()
219  {
220    return replicateSchema;
221  }
222
223  /**
224   * Sets whether to replicate schema or not.
225   * @param replicateSchema whether to replicate schema or not.
226   */
227  public void setReplicateSchema(boolean replicateSchema)
228  {
229    this.replicateSchema = replicateSchema;
230  }
231
232  /**
233   * Returns the data for enabling replication on first server.
234   *
235   * @return the data for enabling replication on first server
236   */
237  EnableReplicationServerData getServer1()
238  {
239    return server1;
240  }
241
242  /**
243   * Returns the data for enabling replication on second server.
244   *
245   * @return the data for enabling replication on second server
246   */
247  EnableReplicationServerData getServer2()
248  {
249    return server2;
250  }
251}