Skip to content

Commit

Permalink
Package YW to be compatible with yugabyte-db
Browse files Browse the repository at this point in the history
Summary:
Added evolutions file and changed var types to be compatible with ysql
Added workaround to #1199 to `yugabyte-db`

Test Plan: `yugabyte-db start --enable_ui`

Reviewers: bogdan, ram

Reviewed By: ram

Subscribers: yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D6976
  • Loading branch information
WesleyW committed Jul 31, 2019
1 parent 89b5ecc commit 169ee07
Show file tree
Hide file tree
Showing 14 changed files with 371 additions and 60 deletions.
105 changes: 66 additions & 39 deletions bin/yugabyte-db
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class YugaByteProcessManager(object):
"{} died unexpectedly. Restarting...".format(p.name), logging.ERROR)
should_callhome = True

<<<<<<< HEAD
# Start or iniitialize yugaware.
if self.wait_yb_master() and self.configs.saved_data.get("webserver_enabled"):
yw_proxy = YugaWareProxy(self.configs.saved_data.get("api_port"))
Expand All @@ -340,53 +341,65 @@ class YugaByteProcessManager(object):
self.init_yw()
process = self.processes.get("yugaware")
process.start()
=======
if self.wait_yb_master():
# Start or iniitialize yugaware after setting YSQL default isolation level.
# This if required to start YW because of
# https://github.com/YugaByte/yugabyte-db/issues/1199.
if self.configs.saved_data.get("webserver_enabled") and self.set_isolation_level():
yw_proxy = YugaWareProxy(self.configs.saved_data.get("api_port"))
if not self.is_yw_initialized():
Output.log("Initiating webserver...")
self.init_yw()
process = self.processes.get("yugaware")
process.start()
>>>>>>> Package YW to be compatible with yugabyte-db

err = self.wait_yw_login(yw_proxy)
if err:
Output.log_error_and_exit(err)
err = self.wait_yw_login(yw_proxy)
if err:
Output.log_error_and_exit(err)

err = yw_proxy.import_universe(self.configs.saved_data.get("master_port"))
if err:
Output.log_error_and_exit(err)
err = yw_proxy.import_universe(self.configs.saved_data.get("master_port"))
if err:
Output.log_error_and_exit(err)

# Should yugabyte-db exit if features aren't disabled properly? Retry?
err = yw_proxy.update_features()
should_callhome = True
else:
process = self.processes.get("yugaware")
if not process.is_running():
process.start()
self.wait_yw_login(yw_proxy)
Output.print_and_log(
"Webserver died unexpectedly. Restarting...", logging.ERROR)
# Should yugabyte-db exit if features aren't disabled properly? Retry?
err = yw_proxy.update_features()
should_callhome = True
else:
process = self.processes.get("yugaware")
if not process.is_running():
process.start()
self.wait_yw_login(yw_proxy)
Output.print_and_log(
"Webserver died unexpectedly. Restarting...", logging.ERROR)
should_callhome = True

# Print startup information and start callhome thread on first successful startup.
if is_first_run:
first_run_success = True
for p in self.processes.values():
if not p.is_running():
first_run_success = False
break

if first_run_success and self.is_yb_initialized() and (
not self.configs.saved_data.get("webserver_enabled")
or self.is_yw_initialized()):
status = self.get_status_string() + \
Output.make_green("YugaByte DB started successfully!\n") + \
Output.make_magenta(
"Join us on Slack at {}".format(
Output.make_underline("https://www.yugabyte.com/slack\n")))
Output.print_out(status)

callhome_thread = Thread(target=self.callhome_loop)
callhome_thread.start()
is_first_run = False

if should_callhome:
self.callhome()

# Print startup information and start callhome thread on first successful startup.
if is_first_run:
first_run_success = True
for p in self.processes.values():
if not p.is_running():
first_run_success = False
break

if first_run_success and self.is_yb_initialized() and (
not self.configs.saved_data.get("webserver_enabled")
or self.is_yw_initialized()):
status = self.get_status_string() + \
Output.make_green("YugaByte DB started successfully!\n") + \
Output.make_magenta(
"Join us on Slack at {}".format(
Output.make_underline("https://www.yugabyte.com/slack\n")))
Output.print_out(status)

callhome_thread = Thread(target=self.callhome_loop)
callhome_thread.start()
is_first_run = False


time.sleep(int(self.configs.saved_data.get("polling_interval")))

# Stop callhome. Useful in future if we do anything after quitting.
Expand Down Expand Up @@ -434,6 +447,20 @@ class YugaByteProcessManager(object):
return False
return True

# Sets YSQL default isolation level.
def set_isolation_level(self):
pg_conf = os.path.join(self.configs.saved_data.get("data_dir"), "pg_data/postgresql.conf")
iso_config = "default_transaction_isolation = 'serializable'"
pattern = "^\s*{}$".format(iso_config)
if os.path.exists(pg_conf):
with open(pg_conf, "a+") as f:
for line in f:
if re.match(pattern, line):
return True
f.write(iso_config)
return True
return False

# Rudimentary yb-admin call. TODO: update.
def get_universe_uuid(self):
saved_uuid = self.configs.saved_data.get("universe_uuid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class KeyInfo {
public UUID getProviderUUID() { return this.idKey.providerUUID; }

@Constraints.Required
@Column(nullable = false)
@Column(nullable = false, columnDefinition = "TEXT")
@DbJson
public JsonNode keyInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class AvailabilityZone extends Model {
public String subnet;

@DbJson
@Column(columnDefinition = "TEXT")
public JsonNode config;

public void setConfig(Map<String, String> configMap) {
Expand Down
2 changes: 1 addition & 1 deletion managed/src/main/java/com/yugabyte/yw/models/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum BackupState {
@Column(nullable = false)
public BackupState state;

@Column(nullable = false)
@Column(columnDefinition = "TEXT", nullable = false)
@DbJson
public JsonNode backupInfo;

Expand Down
8 changes: 5 additions & 3 deletions managed/src/main/java/com/yugabyte/yw/models/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

import com.yugabyte.yw.forms.UniverseDefinitionTaskParams.Cluster;

Expand Down Expand Up @@ -46,8 +48,8 @@ public class Customer extends Model {
// it is assumed that there is a single instance of the db. The id space for this field may have
// to be partitioned in case the db is being sharded.
@Id
@GeneratedValue
private Long id;
@SequenceGenerator(name="customer_id_seq", sequenceName="customer_id_seq", allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="customer_id_seq") private Long id;
public Long getCustomerId() { return id; }

@Column(length = 15, unique = true, nullable = false)
Expand Down Expand Up @@ -87,7 +89,7 @@ public void setPassword(String password) {
@Column(nullable = true)
private String apiToken;

@Column(nullable = true)
@Column(nullable = true, columnDefinition = "TEXT")
private JsonNode features;

public Date getAuthTokenIssueDate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static boolean isValid(String type) {
public String name;

@Constraints.Required
@Column(nullable = false)
@Column(nullable = false, columnDefinition = "TEXT")
@DbJson
@JsonIgnore
public JsonNode data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

import com.avaje.ebean.Model;
import com.avaje.ebean.annotation.EnumValue;
Expand Down Expand Up @@ -98,7 +100,10 @@ public String toString(boolean completed) {
}
}

@Id @GeneratedValue
@Id
@SequenceGenerator(
name="customer_task_id_seq", sequenceName="customer_task_id_seq", allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="customer_task_id_seq")
private Long id;

@Constraints.Required
Expand Down
14 changes: 7 additions & 7 deletions managed/src/main/java/com/yugabyte/yw/models/InstanceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public enum VolumeType {
public Integer numCores;

@Constraints.Required
@Column(nullable = false)
@Column(nullable = false, columnDefinition = "float")
public Double memSizeGB;

@Column(columnDefinition = "TEXT")
Expand Down Expand Up @@ -196,8 +196,8 @@ public static class VolumeDetails {
}

public static class InstanceTypeDetails {
public static final int DEFAULT_VOLUME_COUNT = 1;
public static final int DEFAULT_GCP_VOLUME_SIZE_GB = 375;
public static final int DEFAULT_VOLUME_COUNT = 1;
public static final int DEFAULT_GCP_VOLUME_SIZE_GB = 375;

public List<VolumeDetails> volumeDetailsList;
public PublicCloudConstants.Tenancy tenancy;
Expand All @@ -221,12 +221,12 @@ public void setDefaultMountPaths() {
volumeDetailsList.get(idx).mountPath = String.format("/mnt/d%d", idx);
}
}

public static InstanceTypeDetails createGCPDefault() {
InstanceTypeDetails instanceTypeDetails = new InstanceTypeDetails();
instanceTypeDetails.setVolumeDetailsList(DEFAULT_VOLUME_COUNT, DEFAULT_GCP_VOLUME_SIZE_GB,
InstanceTypeDetails instanceTypeDetails = new InstanceTypeDetails();
instanceTypeDetails.setVolumeDetailsList(DEFAULT_VOLUME_COUNT, DEFAULT_GCP_VOLUME_SIZE_GB,
VolumeType.SSD);
return instanceTypeDetails;
return instanceTypeDetails;
}

public static InstanceTypeDetails createGCPInstanceTypeDetails(VolumeType volumeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static class Axis {
public String getKey() { return config_key; }
public void setKey(String key) { this.config_key = key; }

@Column(nullable = false)
@Column(nullable = false, columnDefinition = "TEXT")
@DbJson
private JsonNode config;

Expand Down
4 changes: 2 additions & 2 deletions managed/src/main/java/com/yugabyte/yw/models/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void setCustomerUuid(UUID id) {
}

@Constraints.Required
@Column(nullable = false)
@Column(nullable = false, columnDefinition = "TEXT")
@DbJson
private JsonNode config;

Expand Down Expand Up @@ -140,7 +140,7 @@ public static Provider get(UUID customerUUID, UUID providerUUID) {
/**
* Get all the providers for a given customer uuid
* @param customerUUID, customer uuid
* @return list of cloud providers.
* @return list of cloud providers.
*/
public static List<Provider> getAll(UUID customerUUID) {
return find.where().eq("customer_uuid", customerUUID).findList();
Expand Down
6 changes: 4 additions & 2 deletions managed/src/main/java/com/yugabyte/yw/models/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public class Region extends Model {
@Constraints.Required
public String ybImage;

@Column
@Column(columnDefinition = "float")
public double longitude;

@Column
@Column(columnDefinition = "float")
public double latitude;

public void setLatLon(double latitude, double longitude) {
Expand Down Expand Up @@ -81,6 +81,7 @@ public void setLatLon(double latitude, double longitude) {
public void setActiveFlag(Boolean active) { this.active = active; }

@DbJson
@Column(columnDefinition = "TEXT")
public JsonNode details;

public void setSecurityGroupId(String securityGroupId) {
Expand All @@ -100,6 +101,7 @@ public String getSecurityGroupId() {
}

@DbJson
@Column(columnDefinition = "TEXT")
public JsonNode config;

public void setConfig(Map<String, String> configMap) {
Expand Down
2 changes: 1 addition & 1 deletion managed/src/main/java/com/yugabyte/yw/models/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public enum State {
private long frequency;
public long getFrequency() { return frequency; }

@Column(nullable = false)
@Column(nullable = false, columnDefinition = "TEXT")
@DbJson
private JsonNode taskParams;
public JsonNode getTaskParams() { return taskParams; }
Expand Down
2 changes: 1 addition & 1 deletion managed/src/main/java/com/yugabyte/yw/models/TaskInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public enum State {
// Details of the task, usually a JSON representation of the incoming task. This is used to
// describe the details of the task that is being executed.
@Constraints.Required
@Column(nullable = false)
@Column(columnDefinition = "TEXT default '{}'", nullable = false)
@DbJson
private JsonNode details;

Expand Down
Loading

0 comments on commit 169ee07

Please sign in to comment.